Java:为什么不自动装箱发生在这里吗?
-
21-09-2019 - |
题
这给了我一个错误:
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));
日食:该方法
add(List<Integer>)
在类型Set<List<Integer>>
不适用的参数(List<int[]>
)
我以为 int
应该是autoboxed到 Integer
?
解决方案
虽然int是autoboxed到整数,int[]不Autoboxed到整数[].
该阵列不装箱,只是种类型自己。
看看这个: 如何转换int[]成列表<Integer> 在Java? 为解决方法和根本原因。
其他提示
它将autobox从
Integer i = 1
int ii = i;
但是,你试图把一系列上,当它试图把一系列原语作为一系列的对象,他们是不同的。
不隶属于 StackOverflow