While doing simple program I noticed this issue.
int[] example = new int[10];
List<Integer> exampleList = Arrays.asList(example);// Compilation error here
Compilation error is returned as cannot convert from List<int[]> to List<Integer>
. But List<int>
is not permitted in java so why this kind of compilation error?
I am not questioning about autoboxing here I just wondered how Arrays.asList
can return List<int[]>
.
asList implementation is
public static <T> List<T> asList(T... a) {
return new ArrayList<T>(a);
}
So it is treating int[] as T that is why this is happening.