我有一些抽象类,每个类都超级分为三个或四个具体的类和形式:
public abstract class TypeOfMapObject extends IrrelevantClass implements Serializable, MapObject, Comparable<MapObject>
{
//irrelevant stuff
@Override
public int compareTo(MapObject m)
{
//specific algorithm for natural ordering
}
}
Run Code Online (Sandbox Code Playgroud)
其他地方在我的代码我有一个ArrayList<MapObject>(其被正确填充,我已经检查了)叫tempMapObjectsArray 我希望那种ArrayList使用Collections.sort(tempMapObjectsArray)(或者更确切地说,我想那种ArrayList,似乎Collections.sort()是做到这一点的最好办法,具体办法它排序并不重要).
它没有编译和给出消息(在Netbeans中):
no suitable method found for sort(java.util.ArrayList<Model.MapObject>)
method java.util.Collections.<T>sort(java.util.List<T>,java.util.Comparator<? super T>) is not applicable
(cannot instantiate from arguments because actual and formal argument lists differ in length)
method java.util.Collections.<T>sort(java.util.List<T>) is not applicable
(inferred type does not conform to declared bound(s) …Run Code Online (Sandbox Code Playgroud)