4

This is the implementation of java.util.Arrays.asList: ()

public static <T> List<T> asList(T... a) {
    return new ArrayList<T>(a);
}

How can that compile? I can't find a constructor for ArrayList, AbstractList or AbstractCollection that accepts a parameter like T... och T[].

Source code from:

java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing

1 Answer 1

10

Okay, I think I see the confusion now.

The ArrayList type in question is a nested type within the Arrays class - it's not java.util.ArrayList.

Sign up to request clarification or add additional context in comments.

2 Comments

try to create a ArrayList with a T... arg or a T[]
Edited answer completely - hopefully that'll be more useful :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.