投例外,我有這樣的方法:爪哇 - 可比
private SortedMap<String, SpaceObjectImpl> catalog = new TreeMap<String, SpaceObjectImpl>();
public Collection<SpaceObject> getSpaceObjects(){
SortedSet<SpaceObject> temp = new TreeSet<SpaceObject>(catalog.values());
return temp;
}
的compareTo同時這裏定義:
public int compareTo(SpaceObjectImpl s){
....
}
class SpaceObjectImpl implements SpaceObject
當我運行程序,ClassCastException
被拋出。任何想法爲什麼?
錯誤:
SpaceObjectImpl cannot be cast to java.lang.Comparable(in TreeMap)
你需要有SpaceObjectImpl實現媲美。 – assylias
啊多數民衆贊成它,謝謝.. :) –