Java: Why doesn't autoblock happen here?

This gives me an error:

int[] l = new int[] {0, 2, 192, -1, 3, 9, 2, 2}; int[] l2 = new int[] {9001, 7, 21, 4, -3, 11, 10, 10}; int[] l3 = new int[] {5, 5, 5, 64, 21, 12, 13, 200}; Set<List<Integer>> lists = new HashSet<List<Integer>>(); lists.add(Arrays.asList(l)); 

Eclipse: add(List<Integer>) method add(List<Integer>) in type Set<List<Integer>> not applicable for arguments ( List<int[]> )

I thought int should be auto-boxed before Integer ?

+6
java generics types autoboxing
source share
2 answers

Although int is autoboxed for Integer, int [] is not Autoboxed for Integer [].

Arrays do not fit in the box, only the types themselves.

See the following: How to convert int [] to List <Integer> in Java? for workarounds and root causes.

+15
source share

He will autobox out

 Integer i = 1 int ii = i; 

But you are trying to convert an array, and when it tries to put an array of primitives as an array of objects, they are different.

+1
source share

All Articles