Comparison method violates its general contract
I am sorting by rating which is a double
. Can anyone see why i am getting this error?
Collections.sort(productsMasterList, new Comparator<Product>() {
@Override
public int compare(Product o1, Product o2) {
final double rating1 = o1.getRating();
final double rating2 = o2.getRating();
boolean realisticRating1 = rating1 < 4.8;
boolean realisticRating2 = rating2 < 4.8;
return rating1 > rating2 && realisticRating1 ? -1 : rating2 > rating1 && realisticRating2 ? 1 : 0;
}
});
edit: This is not a duplicate because it is very specific to me. i have seen other answers but i still can't figure out why i am getting this error, my code seems like it should work fine