我试图将性别值传递给LinkedList,但它给出了一个错误。
public class Employee{
private String name;
private String last;
private Gender gender;
private int ID;
Employee(int ID, String name, String last, Gender gender){
this.name=name;
this.last=last;
this.gender=gender;
this.ID=ID;
}
public enum Gender {
M,F
}
}
public static void main(String[] args){
List<Employee> oopClass = new LinkedList<>();
oopClass.add(100,"Mick","tayson",M);
oopClass.add(101,"Jonny","Tayson",F );
oopClass.add(108,"Barack","Obama",F);
oopClass.add(105,"Vlad","Putin",M);
}
你应该添加Employee的实例到List:
oopClass.add(new Employee(100,"Mick","tayson",M));
oopClass.add(new Employee(101,"Jonny","Tayson",F));
oopClass.add(new Employee(108,"Barack","Obama",F));
oopClass.add(new Employee(105,"Vlad","Putin",M));
需要将Employee实例添加到链表中。修改
oopClass.add(100,"Mick","tayson",M);
oopClass.add(101,"Jonny","Tayson",F );
oopClass.add(108,"Barack","Obama",F);
oopClass.add(105,"Vlad","Putin",M);
oopClass.add(new Employee(100,"Mick","tayson",M));
oopClass.add(new Employee(101,"Jonny","Tayson",F ));
oopClass.add(new Employee(108,"Barack","Obama",F));
oopClass.add(new Employee(105,"Vlad","Putin",M));