我有一个float [],我想得到一个具有相同元素的列表.我可以做一个又一个添加它们的丑陋的事情,但我想使用Arrays.asList方法.但是有一个问题.这有效:
List<Integer> list = Arrays.asList(1,2,3,4,5);
Run Code Online (Sandbox Code Playgroud)
但事实并非如此.
int[] ints = new int[] {1,2,3,4,5};
List<Integer> list = Arrays.asList(ints);
Run Code Online (Sandbox Code Playgroud)
asList方法接受一个varargs参数,对我来说,扩展是一个数组的"简写".
问题:
为什么第二段代码返回List<int[]>但不返回List<int>.
有没有办法纠正它?
为什么自动装箱不在这里工作; 即int[]到Integer[]?