? Extends e: Can receive subtypes of type E or E. Ceiling.
? Super E: Can receive the Type E or the parent of E. Lower
<? Extends class> is a type of restriction wildcard that can accept all <Class> and Class subtypes. However, the cost of the call is read-only access
- list<? Super fruit> list = new arraylist<apple> ();
- List.add (new Apple ()); Can be
- List.add (new Fruit ()); Can be
- list<? extends fruit> list = new arraylist<apple> ();
- Why can't I join the subclasses of the fruit class and the fruit class in the list because of this?
- list<? extends fruit> indicates that the upper limit is Fruit, and the following assignments are legal
- list<? extends fruit> list1 = new arraylist<fruit> ();
- list<? extends fruit> list2 = new arraylist<apple> ();
- list<? extends fruit> list3 = new arraylist<jonathan> ();
- If list<? extends fruit> Support the method of the Add method is valid
- List1 can add fruit and all fruit subclasses
- List2 can add apple and all Apple sub-classes
- List3 can add Jonathan and all of Jonathan's subclasses
- In that case, the problem will arise.
- list<? extends fruit> should hold the object is Fruit subclass, and specifically which one
- Subclasses are still unknown, so adding any subclass of fruit will be problematic, because if the add Apple
- words, may list<? extends fruit> holds the object is new arraylist<jonathan> ()
- Apple's accession is certainly not going to work if if add Jonathan
- words, may list<? extends Fruit> holds a subclass of new Arraylist<jonathan > ()
- Jonathan's accession is not legal, so list< extends fruit> list cannot be add
- and list<? The Super fruit> list indicates that the list holds objects that are Fruit's parent class, and the lower bound is Fruit, so the list of add Fruit or Fruit subclasses is not a problem
? Extends E;? Super E