Implementations and Collections

后端 未结 4 1831
北海茫月
北海茫月 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-21 13:01

    Because the generic type must always be the same, not something that extends from it you can rewrite like this for it to work:

    public ArrayList getEdges() {
    
    return A;
    
    //A is an Arraylist of type 'Action'. Action implements Edge.
    
    }
    

提交回复
热议问题