}
class Student implements Comparable
{
private String name;
private int age;
Student(String name,int age)
{
this.name=name;
this.age=age;
}
public int comparaTo(Object obj)
{
if(!(obj instanceof Student))
throw new RuntimeException("不是学生对象");
Student s=(Student)obj;
if(this.age>s.age)
return 1;
if(this.age==s.age)
return 0;
return -1;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
}
提示有一个错误异常
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The type Student must implement the inherited abstract method Comparable.compareTo(Object)