Page 1 of 1

About Question enthuware.ocpjp.v8.2.1518 :

Posted: Sun Aug 26, 2018 4:00 am
by md4422
the correct answer is any combination of
interests.hashCode(),
name.hashCode(), and
age

right?

interests.hashCode() + name.hashCode() is marked wrong

Re: About Question enthuware.ocpjp.v8.2.1518 :

Posted: Sun Aug 26, 2018 7:38 am
by admin
The equals method of the given class uses age (along with name). Therefore, interests.hashCode() + name.hashCode() cannot be correct for the hashCode method because it doesn't use age.
You need to make sure that if equals method return true for two objects then their hashcodes must also be same. interests.hashCode() + name.hashCode() doesn't ensure that.

Re: About Question enthuware.ocpjp.v8.2.1518 :

Posted: Sun Aug 26, 2018 10:05 am
by md4422
admin wrote:
Sun Aug 26, 2018 7:38 am
The equals method of the given class uses age (along with name). Therefore, interests.hashCode() + name.hashCode() cannot be correct for the hashCode method because it doesn't use age.
You need to make sure that if equals method return true for two objects then their hashcodes must also be same. interests.hashCode() + name.hashCode() doesn't ensure that.
you're absolutely correct. It even said it there. the "trick" is that two objects with different interests can still be .equal()

sorry for wasting your time with my idiocy. my brain went into power save mode there :)