About Question com.enthuware.ets.scjp.v6.2.90 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scjp.v6.2.90 :

Post by ETS User »

I thought the book would be the one in the map because Book overrode .equals() to check the isbn number.

Online
admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.90 :

Post by admin »

Remember that, before comparing the objects with equals() method, a map first tries to locate the bucket in which it thinks it will find the object. It locates the bucket using hashcode of the key object passed in get(key) or put(key, object).

Now, if you do not implement the hashcode, object class's hashcode() will be used. So when you put the original Book object, it's hashcode will be different from the book object that you pass in get(book). Thus, it will not find the right bucket and so it will not be able to find the original book object.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 40 guests