This question already has answers here:
Why we can't do List<Parent> mylist = ArrayList<child>(); [duplicate]
                                
                                    (3个答案)
                                
                        
                4年前关闭。
            
        

为什么

AbstractList<AbstractList<Number>> list = new Vector<Vector<Number>();


产生以下错误:

Type mismatch: cannot convert from Vector<Vector<Number>> to AbstractList<AbstractList<Number>>


而Vector扩展了AbstractList?

最佳答案

使用Java泛型时,必须使用? extends AbstractList

AbstractList<? extends AbstractList<Number>> list = new Vector<Vector<Number>>();

07-26 06:12