A
Arne Vajhøj
Does it shouldn't be the case?
A good practice is to write immutable object and in case of mutable object,
I agree with you that hashcode could throw a exception to avoid collection
or map problem.
So, in the most of the cases (immutable object), hashcode and equals MAY be
equivalent and hashCode could be computed «statically» in constuctors and my
equals code is good.
In minor cases (immutable object), hashCode + equals mix is a non-sense
concept, which could lead to very very serious problems with all generic
classes (collection, map, set, generic algo…) and MUST be avoided and
disable by an exception.
You may argue that most objects should be immutable, but they
are not.
And there are cases where they should not - and this includes
the domain of the original post.
Arne