Suppose I need TreeSet with elements sorted with some domain logic. By this logic it doesn\'t matter order of some elements that doesn\'t equal so compare metho
Yes, as others said above, hashCode() is not secure to use here. But if you dont care about the ordering of objects that are equal in terms of o1.compareTo(o2) == 0, you could do something like:
public int compare(Foo o1, Foo o2) {
int res = o1.compareTo(o2);
if (res == 0 && !o1.equals(o2)) {
return -1;
}
return res;
}