Page 1 of 1
About Question com.enthuware.ets.scjp.v6.2.759 :
Posted: Fri Aug 03, 2012 10:07 am
by ETS User
The instructions on this question are less than helpful.
Re: About Question com.enthuware.ets.scjp.v6.2.759 :
Posted: Fri Sep 14, 2012 8:34 am
by ETS User
It should be obvious that you have to provide a correct implementation of hashCode that meets the contracts of both equals and hashCode. It should be an automatic response to check for this.
The rule of thumb is that if a member is used in hashCode, it must be used in equals. The opposite is not true, however, as we see in this question.
Re: About Question com.enthuware.ets.scjp.v6.2.759 :
Posted: Thu Jan 29, 2015 7:07 am
by aitorbk
I fully agree with the reply: if you use a member not used in equals, you are breaking the contract:if they are equal they should have the same hashcode, and if you use interests, they would be "equal" but with a different hashcode!!