这给了我一个错误:

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;

但是,你试图把一系列上,当它试图把一系列原语作为一系列的对象,他们是不同的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top