> public class TreeSet<E>
> extends AbstractSet<E>
> implements SortedSet<E>, Cloneable,
Generic class declaration:
The "parameter" E is replaced by the programmer when using the class, e.g. TreeSet<String>.
> public boolean addAll(Collection<? extends E> c)
Wildcard generic parameter: It means that the parameter can be any
generic Collection where the parametrized type extends the collection.
So if you have
class Foo { ...
class Fie extends Foo { ...
set = new TreeSet<Foo>();
otherCollection = new ArrayList<Fie>();
you can do a
set.addAll(otherCollection);
because the generic parameter for the second declaration is a class
that extends the parameter class of the first.
http://www.
[
本帖最后由 sunboy_2050 于 2011-11-18 18:03 编辑 ]