Reputation: 1
Below expression is having no issue-
Object obj = new int[] { 1, 2, 3 };
but below two have compile time issue-
Integer i = new int[] { 1, 2, 3 };
int j = new int[] {1,2,3};
why?
Upvotes: -2
Views: 36
Reputation: 272307
var array = new int[]{1,2,3}
is of type int[]
, not an integer.
In Java, an array has a superclass of Object
. Hence assigning that array to an Object
is correct (if practically useless)
Upvotes: 2