inheritance - how to use inheritence in ArrayList in java? -
this question has answer here:
i hava class called qgnode
extends gnode
, class qgraph
extends graph
. in qgnode
constructor when call super
constructor argument arraylist<qgnode>
error occurs. misunderstand inheritance?
here code:
0 public class questiongraph extends graph{ 1 2 public questiongraph(arraylist<qgnode> nodes) { 3 super(nodes); 4 } 5 } 1 public class graph { 2 3 arraylist<gnode> nodes; 4 5 public graph(arraylist<gnode> nodes) { 6 this.nodes = nodes; 7 } 8 }
error occurs @ line 3 , it's syntax error , ide suggest : create method (java.util.arraylist) in questiongraph
inheritance in generics works bit differently. in java arraylist<qgnode>
not subtype of arraylist<gnode>
.
Comments
Post a Comment