Felix Meschberger wrote:
Hi,

Just a small clarification...

Stefan Guggisberg schrieb:

regarding missing hashCode(): i intentionally do never override hashCode()
for mutable objects. hashCode() should imo only be implemented for immutable objects.


Unfortunately this is not in line with the general contract of the hashCode and equals methods, which says - amongst other things - that for two objects being equal according to equals the hashCode must be the same. If you do not overwrite the hashCode method whenever you overwrite the equals method, you will get into troubles. Josh Bloch has written a nice text on this issue in his famous book.

yes, you run into problems when inserting objects that override equals() but not hashcode() into Set's for example.

Reply via email to