码迷,mamicode.com
首页 > 其他好文 > 详细

泛型的问题

时间:2014-12-03 01:41:16      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   java   strong   on   

今天发现了一个问题,不知道怎么回事。还请博友解答。

下面是我的代码:

package aaa;
public class A
{
    
}
package aaa;
public class B extends A
{
    
}
package aaa;
public class C extends B
{
    
}
package aaa;

import java.util.LinkedList;
import java.util.List;

public class Main
{
    public static void main(String[] args[]){
        List<? extends B> eBList = new LinkedList<>();
        List<? super B> sBList = new LinkedList<>();
        A a = new A();
        B b= new B();
        C c = new C();
        eBList.add(a);
        sBList.add(c);
    }
}

这个eBList.add(a);为什么会报错?

泛型的问题

标签:style   blog   io   ar   color   sp   java   strong   on   

原文地址:http://www.cnblogs.com/lucian/p/4138971.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!