I have a class for which equality (as per equals()
) must be defined by the object identity, i.e. this == other
.
I want to implement Comparable
to order such objects (say by some getName()
property). To be consistent with equals()
, compareTo()
must not return 0
, even if two objects have the same name.
Is there a way to compare object identities in the sense of compareTo
? I could compare System.identityHashCode(o)
, but that would still return 0
in case of hash collisions.