java - Type mismatch: cannot convert from element type Object to Parent -


i'm trying develop e4 application have error : in part "error:type mismatch: cannot convert element type object parent" please in advance :)

@creatable @singleton public class treecontrol {     parentsholder parentholder = new parentsholder();      public parent parentexists(string str) {         (parent p : parentholder.getparents())             if (p.gettag().equals(str))                 return p;         return null;     }      public child childexists(string p, string c) {         parent parent = parentexists(p);         if (parent != null)             (child child : parent.getchildren())                 if (child.gettag().equals(c))                     return child;         return null;     } } 

this parent holder class

public class parentsholder extends model {     list parents = new arraylist();      public list getparents() {         return parents;     }      public void setparents(list parents) {         firepropertychange("parents", this.parents, this.parents = parents);     }          public void addparent(parent p) {             list newlist = new arraylist<>(parents);             newlist.add(p);             setparents(newlist);         }     } 

and error in line

for (parent p : parentholder.getparents()) 

and line:

   (child child : parent.getchildren()) 

you using 'raw type' list list java not know list of parent objects , can treat list of object.

you need use generics specify list type - everywhere have list should list<parent>.

so like:

public class parentsholder extends model {     list<parent> parents = new arraylist<>();      public list<parent> getparents() {         return parents;     }      public void setparents(list<parent> parents) {         firepropertychange("parents", this.parents, this.parents = parents);     }      public void addparent(parent p) {         list<parent> newlist = new arraylist<>(parents);         newlist.add(p);         setparents(newlist);     } } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -