我可以使用 compareTo 对整数和双精度值进行排序吗?我的系统给了我一个错误,我无法在原始类型 int 上调用 compareTo(int)。有任何想法吗?
代码:
public int compare(Object o1, Object o2) {
Record o1C = (Record)o1;
Record o2C = (Record)o2;
return o1C.getPrice().compareTo(o2C.getPrice());
}
class Record
public class Record {
String name;
int price;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}