我有这个 :
Offers eoResponse = eoClient.getOffers(url);
Collections.sort(eoResponse, new Comparator<Offer>() {
public int compare(Offer offer1, Offer offer2) {
return offer1.getAmount().compareToIgnoreCase(offer2.getAmount()); // errors in this line cannot resolve method compareToIgnoreCase(float)
}
});
Run Code Online (Sandbox Code Playgroud)
我想要比价格排序我的arraylist,但我有这个错误:
cannot resolve method compareToIgnoreCase(float)
Run Code Online (Sandbox Code Playgroud)
怎么了
听起来你可能想要:
return Float.compare(offer1.getAmount(), offer2.getAmount());
Run Code Online (Sandbox Code Playgroud)
那就是getAmount()返回一个float- 这意味着你将无法直接调用它上面的方法,但这Float.compare是一个方便的解决方法.
如果getAmount()实际返回a Float(并且您知道它将为非null),您可以使用:
return offer1.getAmount(),compare(offer2.getAmount());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
746 次 |
| 最近记录: |