- 1 public static void main(String[] args) {
- 2 Listsuper Apple > list5 = new ArrayList();
- 3 test1(list5);
- 4 Listsuper FujiApple > list6 = new ArrayList();
- 5 // test1(list6); // List<? super FujiApple> 类型的范围超过了List<? super Apple>因此无法调用
- 6 Listsuper Apple > list7 = new ArrayList();
- 7 test1(list7);
- 8 Listsuper Apple > list8 = new ArrayList();
- 9 test1(list8);
- 10
- }
- 11 12 public static void test1(Listsuper Apple > list) {
- 13 list.add(new FujiApple());
- 14 list.add(new Apple());
- 15 // list.add(new Fruit()); //这里Fruit类型为Apple的父类,容器list在确保安全的情况下最高只能添加Apple类的对象
- 16 list.add(null);
- 17
- }
来源: http://www.bubuko.com/infodetail-1949173.html