Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
781 views
in Technique[技术] by (71.8m points)

java - Arrays.asList() Confusing source code

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);
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

java.util.Arrays.ArrayList is a different class than java.util.ArrayList.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...