日期:2014-05-18  浏览次数:21437 次

<? extends T> 与 <? super T>的区别,求解

import java.util.ArrayList;
import java.util.List;

public class Test {

    public static void main(String[] args) throws SQLException {

       List<? super Fruit> f0=new ArrayList<Fruit>();
       f0.add(new Apple());
       f0.add(new Fruit());
       f0.add(new SupApple());
       
       List<? super Fruit> f1=new ArrayList<Apple>();
       f1.add(new Apple());
       f1.add(new Fruit());
       
       List<? extends Fruit> f2=new ArrayList<Fruit>();
       f2.add(new Apple());
       f2.add(new Fruit());
       
       
       List<? extends Fruit> f3=new ArrayList<Apple>();
       f3.add(new Apple());
       f3.add(new Fruit());
       // f.add(new Apple());
        
       List<? super Apple> f5=new ArrayList<Fruit>();
       f5.add(new Apple());
       f5.add(new SupApple());
       f5.add(new Fruit());
    }
}

class Fruit{
}

class Apple extends Fruit{
}

class SupApple extends Apple{    
}


代码如上,请大家指导,上述代码有多处编译报错,求解:泛型中  extends 和 super的区别!

------解决方案--------------------
友情链接: 爱易网 云虚拟主机技术 云服务器技术 程序设计技术 开发网站 APP开发教程
Copyright © 2013-2026 爱易网页 当前在线:306人  网站在22分13秒内访问总人数:4385人 9秒前 60.24%  粤ICP备18100884号-2