Eclipse上的Java项目
maven-资源-插件2.7
JDK/JRE 13
Eclipse EE 4.15
结构
public interface Frequency {
public int increment();
public int decrement();
public int freq();
public Object getTop();
}下面的类需要实现接口Freq
public class Child extends IndexedWord implements Frequency{
int freq;
TreeSet<Relation> relations;
public Child() {
freq=0;
relations = new TreeSet<Relation>(new FreqCompare<Relation>());
}
public void addRelation(Relation relation) {
relations.add(relation);
}
public Relation getTop() {
Relation top=relations.first();
top.decrement();
return top;
}
@Override
public int increment() {
freq++;
return freq;
}
@Override
public int decrement() {
freq--;
return freq;
}
@Override
public int freq() {
return freq;
}
@Override
public int compareTo(Object obj) {
return 0;
}
}臭虫
Eclipse拒绝编译该项目。在compareTO()的声明上徘徊时,我得到
方法compareTo(对象)必须重写或实现超类型方法
我试过的
使用不同的JDK版本
重新生成.settings、.classpath、.project文件/文件夹
编辑:解决方案
我修改了类以实现频率和可比较性
发布于 2020-06-30 17:09:06
根据Java规范,对于不覆盖或不实现@Override的方法,拥有是一个错误。
在您的示例中,您必须删除此方法的实现,或者至少删除@Override注释,以获得有效的Comparable代码或更改该方法覆盖或实现的代码,例如添加添加Comparable接口(例如Frequency extends Comparable或Child extends IndexedWord implements Frequency, Comparable或IndexedWord implements Comparable或.)。
https://stackoverflow.com/questions/62662339
复制相似问题