我正在尝试实现comparable
以使用Arrays.sort(array)
但由于某种原因它没有compareTo
在超类中找到该方法。我正在尝试比较字符串仅供参考。
编辑:对不起,我忘了添加我得到的错误。这里是:
Employee.java:32: error: cannot find symbol
return super.compareTo((Object)other);
^
symbol: method compareTo(Object)
代码:
public abstract class Employee implements Cloneable, Comparable
{
private Name name;
private double weeklyPay;
public Employee(String first, String middle, String last, double weeklyPay)
{
this.weeklyPay = weeklyPay;
name = new Name(first,middle,last);
}
public Employee(String last, double weeklyPay)
{
this.name = name;
this.weeklyPay = weeklyPay;
name = new Name(last);
}
public Employee(String first, String last, double weeklyPay)
{
this.name = name;
this.weeklyPay = weeklyPay;
name = new Name(first,last);
}
public abstract double getWeeklyPay();
public String getFullName()
{
return name.getFullName();
}
public int compareTo(Object other)
{
return super.compareTo((Object)other);
}
public int compareTo(Name name)
{
return compareTo((Object)name.getFullName());
}