List<Employeee> employees = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
String[] input = new String[6];
int n = Integer.valueOf(scanner.nextLine());
for (int i = 0; i < n; i++) {
input = scanner.nextLine().split(" ");
employees.add(new Employeee(input[0], Double.parseDouble(input[1]), input[2], input[3], input[4],
Integer.valueOf(input[5])));
}
for (Object i : employees) {
System.out.println(i.sallary); //And here ofc idk what to do to print them
System.out.println(i.name);
}
所以这里我只是从我的自定义类中创建一些对象,然后将它们放在列表中。 然后我用for循环遍历该列表,并且我想要打印它们的属性,但它不会让我。我的员工课程很简单我甚至不会粘贴其中的getter和setter。
public class Employeee {
private String name;
private double sallary;
private String possition;
private String department;
private String email;
private int age;
public Employeee(String name, double sallary, String possition, String department, String email, int age) {
this.name = name;
this.sallary = sallary;
this.possition = possition;
this.department = department;
this.email = email;
this.age = age;
}
}
答案 0 :(得分:0)
这里有很多问题。
didAddSubview:
的for-each语句中使用Object
。Employee
,这意味着您不能。您应该使用相应的访问者功能。