Implementations and Collections

后端 未结 4 1830
北海茫月
北海茫月 2020-12-21 12:24

Why does this not work...

public ArrayList getEdges() {

return A;

//A is an Arraylist of type \'Action\'. Action implements Ed         


        
4条回答
  •  星月不相逢
    2020-12-21 13:05

    A banana is a fruit. A list of bananas is not a list of fruit.

    Oherwise someone could construct a list of bananas, pass you a reference to a list of fruit, and you'd (correctly) insert an apple in it. The owner of the list of the bananas would be rightfully surprised.

提交回复
热议问题