报错
Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!
原因在于比较的值中有NaN,所以不能用下面的compareTo,要用Double类中的compareTo
NaN(
A constant holding a Not-a-Number (NaN) value of type double.)
public int compareTo(Data o) {
if(distance > o.getDistance()){
return -1;
}else if (distance < o.getDistance()){
return 1;
}else
return 0;
}
改为
public int compareTo(Data o) {
return -Double.compare(o.distance, this.distance);
}