我有这个方法:
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)