Codename One不接受原始类型(int),因此我尝试使用Integer编写以下比较器:
private static class CelebrityPopularityComparator implements Comparator<Celebrity> {
@Override
public int compare(Celebrity celebrity1, Celebrity celebrity2) {
Integer celebrity1PopularitySum = celebrity1.getCelebrityPopularitySum();
Integer celebrity2PopularitySum = celebrity2.getCelebrityPopularitySum();
Integer comparisonResult = Integer.valueOf(celebrity1PopularitySum.compareTo(celebrity2PopularitySum));
return comparisonResult;
}
}
我尝试了许多方法,但它只是不起作用。它不会将构建发送到服务器。我该怎么办才能修复它?谢谢!
答案 0 :(得分:2)
试试这个:
Integer celebrity1PopularitySum = celebrity1.getCelebrityPopularitySum();
Integer celebrity2PopularitySum = celebrity2.getCelebrityPopularitySum();
if(celebrity1PopularitySum.equals(celebrity2PopularitySum)){
return 0;
}else if(celebrity1PopularitySum.intValue() < celebrity2PopularitySum.intValue()){
return -1;
}else{
return 1;
}