重写报错The type ** must implement the inherited abstract method Comparable.compareTo(Object)

重写报错The type ** must implement the inherited abstract method Comparable.compareTo(Object),第1张

重写报错The type ** must implement the inherited abstract method Comparable.compareTo(Object) The type Student must implement the inherited abstract method Comparable.compareTo(Object) 重写compareTo()方法报错

参考链接: 实现 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 + "]";
	}
	
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/zaji/5706795.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存