public int compareTo(Object another) throws CustomMadeException
{
if(this.getClass() != another.getClass())
{
throw new CustomMadeException();
}
Car other = (Car) another;
return this.getBrand().compareTo(other.getBrand());
}
我不明白什么是我的代码完全错了。为什么它不能实现可比较的T?我是否必须将compareTo的参数更改为T?但是它不应该是Object吗?据我所知,compareTo在界面上的实现可比较是空白的。错误:在汽车compareTo(对象)无法实现比较(T)在比较
好的,但不应该是Object吗?它是equals()的对象吧? – user2089523 2013-03-23 20:20:39
错误:汽车不是抽象的,并且不会覆盖比较中的抽象方法compareTo(Object) – user2089523 2013-03-23 20:21:31
@ user2089523:您是否按照我的答案执行“Comparable”? –
NPE
2013-03-23 20:22:26