问题描述
根据,该方法 asList
传递一个数组构造新的ArrayList
。但是,有没有这样的构造。不可变参数生成一个数组,所以这怎么可能?
下面是 asList
来源:
公共静态< T>清单< T> asList(T ...一){
返回新的ArrayList< T>(一);
}
<一个href=\"http://grep$c$c.com/file/repository.grep$c$c.com/java/root/jdk/openjdk/8u40-b25/java/util/Arrays.java#Arrays.ArrayList\"相对=nofollow> java.util.Arrays.ArrayList
是不同的类比<一个href=\"http://grep$c$c.com/file/repository.grep$c$c.com/java/root/jdk/openjdk/8u40-b25/java/util/ArrayList.java#ArrayList\"相对=nofollow> 的java.util.ArrayList
。
According to this source code for the Arrays
class, the method asList
passes an array to the constructor of new ArrayList
. But there is no such constructor. Doesn't varargs generate an array, so how is this possible?
Here is the asList
source:
public static <T> List<T> asList(T... a) {
return new ArrayList<T>(a);
}
java.util.Arrays.ArrayList
is a different class than java.util.ArrayList
.
这篇关于Arrays.asList()混淆源$ C $ C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!