Arrays.asList()混淆源$ C ​​$ C [英] Arrays.asList() Confusing source code

查看:210
本文介绍了Arrays.asList()混淆源$ C ​​$ C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据阵列类此源$ C ​​$ C ,该方法 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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