一、原因
出现上面错误的原因是,类UserInfo在ComparatorTest2中
public class ComparatorTest2 {
public static void main(String[] args) {
UserInfo u1 = new UserInfo();
}
class UserInfo{
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
}
二、解决方案
将类UserInfo移出去就好了