下面这段代码 报了一个异常 我该怎么解决呢?xception in thread "main" java.lang.ClassCastException: com.itheima.Student cannot be cast to java.lang.Comparable
package com.itheima;
import java.util.Iterator;
import java.util.TreeSet;
class Student {
static String name;
static int age;
static int score;
Student(String name, int age, int score) {
Student.name = name;
Student.age = age;
Student.score = score;
}
}
public class Test10 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student stu1 = new Student("wangda", 21, 98);
Student stu2 = new Student("liuer", 25, 95);
Student stu3 = new Student("zhangsa", 29, 89);
Student stu4 = new Student("lisi", 25, 92);
Student stu5 = new Student("zhaowu", 43, 93);
TreeSet<Student> st = new TreeSet<Student>();
st.add(stu1);
st.add(stu2);
st.add(stu3);
st.add(stu4);
st.add(stu5);
Iterator<Student> it = st.iterator();
while (it.hasNext()) {
System.out.println(it.hasNext());
}
}
}
|