Java lower bounded type List as parameter -


hello got 2 classes: person class , employee class extends person simple

public class person {     private string name;     private string surname;      public string getname() {         return name;     }     public void setname(string name) {         this.name = name;     }     public string getsurname() {         return surname;     }     public void setsurname(string surname) {         this.surname = surname;     }     public person(string name, string surname) {         super();         this.name = name;         this.surname = surname;     }   }  public class employee extends person {     private string salary;     private string position;     public string getsalary() {         return salary;     }     public void setsalary(string salary) {         this.salary = salary;     }     public string getposition() {         return position;     }     public void setposition(string position) {         this.position = position;     }     public employee(string name, string surname, string salary, string position) {         super(name, surname);         this.salary = salary;         this.position = position;     }    } 

i want write function adding person lower bounded parametrized list

public class auxiliaryclass {     public static void addtolist(list<? super employee> list){         person osoba1 = new person("czeslaw","spiewa");         list.add(osoba1);     }   } 

but eclipse doesn't allow error message: "the method add(capture#1-of ?super employee)in type list not applicable arguments (person)

list<? super employee> means "a list of unknown concrete class x, superclass of employee.

it should clear why cannot add object of type person list: person not x.

perhaps, of more help, if explained trying here.

update: actually, take back. person is x, because subclass of employee, subclass of x. should possible add list. looks eclipse full of it. javac (1.8) lets me this, , intellij.

sorry confusion.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -