【发布时间】:2016-10-01 07:39:26
【问题描述】:
我创建了Comparator<Entity> 的实现,但是当我使用此比较器对Array<Entity> 进行排序时。我将收到java.lang.NullPointerException,因为当我将实体映射到已删除的静态集合时。现在我的问题是我不知道要返回什么来跳过比较方法。
public class CustomComparator implements Comparator<Entity> {
public int compare(Entity e1, Entity e2) {
if( e1== null || e2 == null) {
return // don't know what to return to skip this method;
}
Vector2 e1Pos = Mapper.transform.get(e1).position;
Vector2 e2Pos = Mapper.transform.get(e2).position;
}
}
【问题讨论】:
-
只有当您的
Array包含空元素时才会发生这种情况。解决方法:不要。
标签: java libgdx comparator