我的班级标题:
public class GraphEdge implements Comparable<GraphEdge>{
/** Node from which this edge starts*/
protected Point from;
/** Node to which this edge goes*/
protected Point to;
/** Label or cost for this edge*/
protected int cost;
我的 compareTo 方法:
@Override
public int compareTo(GraphEdge other){
return this.cost-other.cost;
}
但 Eclipse 给了我错误:
GraphEdge 类型的方法 compareTo(GraphEdge) 必须覆盖超类方法
为什么?我试着做 Comparable,与
@Override
public int compareTo(Object o){
GraphEdge other = (GraphEdge) o;
return this.cost-other.cost;
}
但这也失败了。