我正在尝试将性别值传递给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实例添加到列表中:
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));
关于java - 在LinkedList中使用枚举值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30679847/