为什么Arrays.asList上一个int []返回一个List< INT []>和不是List< INT&GT ;?

为什么Arrays.asList上一个int []返回一个List< INT []>和不是List< INT&GT ;?

问题描述:

考虑这个code:

int[] tcc = {1,2,3};
ArrayList<Integer> tc = Arrays.asList(tcc);

针对上述情况,Java的抱怨说,它不能从转换列表&LT; INT []&GT; 的ArrayList&LT;整数GT;

这有什么错呢?

为什么列表&LT; INT []&GT; ,而不是列表&LT; INT&GT;

一个ArrayList只能容纳对象不语,如整型,而且由于INT!=整数你不能做你想要使用数组做什么原语,就这么简单。这将为整型数组,虽然工作。

An ArrayList can hold only objects not primitives such as ints, and since int != Integer you can't do what you're trying to do with an array of primitives, simple as that. This will work for an array of Integer though.