As far as I know, things like SortedMapor SortedSet, use compareTo(and not equals) for types Comparable<?>to check for equality ( contains, containsKey).
But what if certain types are equivalent in concept and not comparable?
(Hash codes, memory addresses, ...)
I need to declare Comparator<?>and override the method int compareTo(T o1, To2). Well, I can return 0 for instances that are considered equal. But, for unsubstantiated cases, what do I return when the order is not obvious?
Is the approach of using SortedMap or SortedSet on equatable , but (on the concept) is not comparable to the type of good, in any case?
Thank!
EDIT:
I don't want to keep things sorted, but I would use a “regular” map and set, I could not “override” the equality behavior.
EDIT 2:
Why can't I just override equals(...):
I need to change the behavior of foreign class equality. I can’t edit it.
EDIT 3:
Think of .NET: they have an IEquatable interface that the cat modifies equality behavior without touching comparable behavior.
4:
compareTo return 0 1 ? ? , , SortedMap/SortedSet compareTo . , , ? . * . , .
. 1 .
5:
? ? : Comparator?
6:
Mark Peters waxwing . , equals hashCode, .