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> lists = new HashSet<List>(); lists.add(Arrays.asList(l));
Eclipse:类型
Set<List>
的方法add(List)
不适用于参数(List
)
我以为int
应该被自动提交给Integer
?
虽然int被自动装箱为Integer,但int []不会自动装箱到Integer []。
数组不是盒装的,只是类型本身。
请参阅: 如何在Java中将int []转换为List
它会自动装箱
Integer i = 1 int ii = i;
但是,你试图转换一个数组,当它试图将一个基元数组作为一个对象数组时,它们是不同的。