栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

重写报错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 + "]";
	}
	
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/708252.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号