我有以下实现Comparable
接口的类。我已经在其中定义了compareTo()
方法,但不知何故编译器仍然告诉我我必须实现它。
public class Person implements Comparable {
private String fName;
private String lName;
private Integer age;
public Person (String fName, String lName, int age)
{
this.fName = fName;
this.lName = lName;
this.age = age;
}
// Compare ages, if ages match then compare last names
public int compareTo(Person o) {
int thisCmp = age.compareTo(o.age);
return (thisCmp != 0 ? thisCmp : lName.compareTo(o.Name));
}
}
错误信息:
The type Person must implement the inherited abstract method Comparable.compareTo(Object)
Syntax error on token "=", delete this token
at me.myname.mypkg.Person.<init>(Person.java:6)
我很肯定我不必Object
在该compareTo()
方法中强制转换为根类。那么我做错了什么?