public class TestSet {
public static void main(String[] args) {
TreeSet<Student> se = new TreeSet<Student>();
Student s1 = new Student("张三",90);
Student s2 = new Student("王五",90);
Student s3 = new Student("赵六",90);
se.add(s1);
se.add(s2);
se.add(s3);
// se.add("s");
// se.add("a");
// se.add("c");
Iterator<Student> it = se.iterator();
while(it.hasNext()) {
Student s = it.next();
System.out.println(s.getName() + "-" + s.getAge());
}
}
}
TreeSet 打印 Student 类型的就会出现 类型转换异常,而String类型就没事 ,如果要想打印Student类型的应该怎么办啊?
|