参考链接: 实现 Comparable:“必须实现继承的抽象方法”错误.
public class Student implements Comparable { //报错:The type Student must implement the inherited abstract method Comparable.compareTo(Object) //改为泛型:public class Student implements Comparable{顺利解决 private String stu_name; private int stu_id; private int stu_age; public Student(String name,int id,int age) { this.stu_name = name; this.stu_id = id; this.stu_age = age; } //getter and setter methods @Override public int compareTo(Student stu) { int stu_id = ((Student)stu).getStu_id(); return this.stu_id - stu_id; } @Override public String toString() { return "[stu_name =" + stu_name + "stu_id = " + stu_id + "stu_age = " + stu_age + "]"; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)