public class Human implements Comparable<Human> {
private int age;
private String name;
public Human(String givenName, int age) {
this.name = givenName;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String introduce() {
return "Hey! I'm " + name + " and I'm " + age + " years old.";
}
public int CompareTo(Human h1, Human h2) {
int hum1 = h1.getAge();
int hum2 = h2.getAge();
System.out.println(hum1 - hum2);
}
}
該代碼使用年齡參數排序ArrayList和這個錯誤味精出現人類不是抽象的,不會重寫抽象方法compareTo(Human).solution?
./Human.java:6: error: Human is not abstract and does not override abstract method compareTo(Human) in Comparable public class Human implements Comparable
這裏有什麼錯?請幫助。
您的CompareTo錯誤[link](http://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html#compareTo-T-) –