? super T 语法将泛型类限制为所有T的超类(包括T自身)
T extends Comparable  T为Comparable的子类

解决方案 »

  1.   

    //: generics/SuperTypeWildcards.java
    import java.util.*;public class SuperTypeWildcards {
      static void writeTo(List<? super Apple> apples) {
        apples.add(new Apple());
        apples.add(new Jonathan());
        // apples.add(new Fruit()); // Error
      }
    } ///:~
    ? super T 语法将泛型类限制为所有T的超类(包括T自身)
    T的超类吗,那Apple的超类是Fruit,为什么不能添加呀
      

  2.   

    集合用泛型操作时,装入集合用extends,从集合取出用super
      

  3.   

    (List<? super Apple> apples)
    我想问的是? super Apple代表下界
    是代表参数可为Apple的超类,还是Apple的子类
      

  4.   

    super左侧为父,右侧为子,extends相反
      

  5.   

    PECS原则:ProducerExtends,ConsumerSuper。集合用泛型操作时,装入集合用super,从集合取出用extends。又称Get and Set 原则。