"java.lang.IllegalArgumentException: Comparison method violates its general contract!" error for a Collections.sort() -
this question has answer here:
i trying sort bunch of numbers , have following code:
//sort possible targets based on distance collections.sort(allpossibletargets, new comparator<npd2>() { @override public int compare(npd2 o1, npd2 o2) { if (o1 == null && o2 == null) return 0; if (o1 == null && o2 != null) return 1; if (o1 != null && o2 == null) return -1; return o1.getnpd().getdistance() < o2.getnpd().getdistance() ? -1 : 1; } }); however, above exception. please help. thanks.
you're comparator doesn't return 0 if both objects equal.
see post: comparison method violates general contract in java 7
Comments
Post a Comment