i\'m trying to develop an e4 application but i have an error : in this part \"error:Type mismatch: cannot convert from element type Object to Parent\" any help please thanks in
You are just using the 'raw type' List
for your list so Java does not know that this is a list of Parent
objects and can only treat it as a list of Object
.
You need to use generics to specify the list type - everywhere you have List
it should be List<Parent>
.
So something 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);
}
}
change corresponding lines to below code as:
for(Object p : parentholder.getParents())
{
Parent p1= (Parent)p;
//your code .....
}
similarily for Child class
for(Object p : parentholder.getParents())
{
Child child= (Parent)p;
//your code .....
}