It is clear that equals()(and, of course, hashCode()) are valuable when you are dealing with objects of constant value - map keys, strongly typed field values that need to be compared between objects that contain them, etc.
But besides value objects, how often is it very likely that you will have two independently constructed instances and want them to be equal?
It’s hard for me to imagine a realistic scenario where relational equality would not be de facto, you will get what you want; and in these specific cases, it seems that the equivalent scenario method ( isEquivalentTo(Foo)rather than equals(Object)) will be safer. In particular, for mutable objects?
What is the precedent for equals()non-valuable types?
source
share