Java 泛型 <? super T> 中 super 怎么 理解?与 extends 有何不同?

来源:互联网 发布:telnet 登录linux 编辑:程序博客网 时间:2024/05/03 08:10

Java 泛型 <? super T> 中 super 怎么 理解?与 extends 有何不同?

首先看这段代码

// compile error
// List <? extends Fruit> appList2 = new ArrayList();
// appList2.add(new Fruit());
// appList2.add(new Apple());
// appList2.add(new RedApple());

List <? super Fruit> appList = new ArrayList();
appList.add(new Fruit());
appList.add(new Apple());
appList.add(new RedApple());


0 0