如何Arrays.asList返回一个实例化列表? [英] How can Arrays.asList return an instantiated List?
问题描述
Arrays.asList
返回一个类型的列表。但是,列表是一个接口,这样怎么能实例化?如果试图实例化一个类型列表我得到一个错误说这是不可能的。
Arrays.asList
returns a typed List. But List is an interface so how can it be instantiated? If try and instantiated a typed List I get an error saying it is not possible.
修改
没关系我看这是怎么回事,刚刚通过的文档了一会儿混淆。
Nevermind I see what's going on, just got confused by the docs for a moment.
推荐答案
这是一个 Arrays.ArrayList
这不应该与混淆的Java。 util.ArrayList
。这是,这意味着你做,改变原始数组的任何改变数组的包装,你不能添加或删除条目。通常它是与ArrayList的结合使用像
It's an Arrays.ArrayList
which shouldn't be confused with java.util.ArrayList
. It is a wrapper for the array which means any changes you make, alter the original array, and you can't add or remove entries. Often it is used in combination with ArrayList like
List<String> words = new ArrayList<>(Arrays.asList("Hello", "There", "World"));
这篇关于如何Arrays.asList返回一个实例化列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!