I was talking to some of the people at my new contract here, and I realized I never posted this revelation.
There is an partial solution to that annoying Java equals/compareTo issue. After you know that the object that you are comparing to is apparently equal to you, you then need to return this.hashCode() == them.hashCode(). Assuming people have properly overridden hashCode, this should mostly keep you safe.
Of course, there is the unfortunate possibility that you could get a false positive here: the quality of your hashCode calculation will determine how likely that is. And the this.getClass().equals(them.getClass()) || them.equals(this) can have infinite recursion of two sibling classes are accidentally equal to eachother.
So I’m still struggling with this. Help?
Related posts: