1

I am reading source code of java collection. I have some troubles with the source code of Interface java.util.List.

In the bottom of source code of Interface java.util.List, there is a method:

static <E> List<E> copyOf(Collection<? extends E> coll) {
    return ImmutableCollections.listCopy(coll);
}

I want to ask, what is usage of <? extends E>.

Can I replace <? extends E> with E? Just like this:

static <E> List<E> copyOf(Collection<E> coll) {
    return ImmutableCollections.listCopy(coll);
}

Are two functions doing same things?

If they are same, why use <? extends E>

If they are not same,when I call the method like:

List.copyOf(new ArrayList<Integer>());

what is ?(wildcard), and what is E?

Is E representing Integer?

or ?(wildcard) representing Integer?

10ca1h0st
  • 21
  • 4

0 Answers0