I've got two pieces of code, in both the main focus is the method Arrays.asList(T... a)
.
In the first of them I input an Integer[]
, in the second I input an int[]
, and - this is the part that confuses me, in the two cases, the resulting List<...>
is different:
Integer[] arrayBoxed = new Integer[10];
List<Integer> list = Arrays.asList(arrayBoxed);
It's pretty short, and none of the values in arrayBoxed are set, but it works, and produces an List<Integer>
.
int[] array = new int[10];
List<int[]> list = Arrays.asList(array);
In this case, for some reason, I get a List<int[]>
, which is a pretty pathological construct.
Why is that?
The problem is, that given the similar input into Arrays.asList
, I'd expect both of the functions to output the same (both code pieces are fully functional). However, one time the method returns List<Integer>
, the other time List<int[]>
.