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