Java:为什么不在这里发生自动装箱? [英] Java: Why isn't autoboxing happening here?

查看:101
本文介绍了Java:为什么不在这里发生自动装箱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这给了我一个错误:

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< ( List >) Set []>

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

我认为 int 应该被自动装箱到 Integer

I thought int was supposed to be autoboxed to Integer?

推荐答案

虽然int自动绑定到Integer,int []不自动绑定到Integer []。

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

数组不是装箱的,只是类型本身。

The arrays are not boxed, just the types themselves.

请参阅:如何将int []转换为列表与LT;整数>在Java中?为解决方法和潜在的原因。

See this: How to convert int[] into List<Integer> in Java? for workarounds and the underlying reasons.

这篇关于Java:为什么不在这里发生自动装箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆