2009-11-20 73 views
6

这给了我一个错误:Java:为什么不在这里发生自动装箱?

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: The method add(List<Integer>) in the type Set<List<Integer>> is not applicable for the arguments (List<int[]>)

我以为int本来应该autoboxed到Integer

+0

哦,你的名字是一个设置对象列表! – Cshah 2010-03-11 10:52:33

回答

1

它将从

Integer i = 1 
int ii = i; 

autobox但是,你尝试转换一个数组,当它试图把原语的数组作为对象的数组,它们是不同的。