Monday 15 September 2014

java - Warning when converting between two arraylists holding objects of the same types -



java - Warning when converting between two arraylists holding objects of the same types -

in class node got

private arraylist<node> neighbors; public arraylist<node> getneighbors() { homecoming this.neighbors; }

in class graph got

public void foo(node first) { arraylist<node> firstneighbors = first.getneighbors(); ... }

compiling gives me warning

warning: [unchecked] unchecked conversion arraylist<node> firstneighbors = first.getneighbors(); required: arraylist<node> found: arraylist

does see error here?

the error thrown not code posted,

warning: [unchecked] unchecked conversion arraylist firstneighbors = first.getneighbors();

you need check first object. object should of class a or should subclass of arraylist getneighbors() method.

you ,

classa obj= new classa(); list<node> firstneighbors = obj.getneighbors();

to values method , pass list

java generics arraylist

No comments:

Post a Comment