Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what It means if you don't override equals() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what It means if you don Watch "what It means if you don New topic
Author

what It means if you don't override equals()

aslika bahini
Ranch Hand

Joined: Mar 03, 2007
Posts: 111


I have a doubt in scjp pg 525(K&B)
The above code is the example for car/owner and equals(),hashcode().

question 1: for search I will be in trouble unless i still have a
reference to the exact object used as the key when added it to the
collection(may i know which object is that from the above code)

question 2: one instance added it to collection, essentially re-create
an identical instance to search based on the object as key.
does it mean like this?
car carobj1 = new car("V001Lexus");
Hm.put(carobj1, perobj1);
car carobj8 = new car("V001Lexus");
Hm.get(carobj8);

question 3: more than one object representing a single unique car can
exist( does this sentence mean this?)

Hm.put(carobj1,perobj1);
Hm.put(carobj1,perobj2);
Hm.put(carobj1,perobj3);
Hm.put(carobj1,perobj4);

which is something like overwriting different owner to the
same car

is my understanding right?


Thanks for your patience and valuable time for replying.

samura




Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
If this link may help you!


Thanks,


cmbhatt
aslika bahini
Ranch Hand

Joined: Mar 03, 2007
Posts: 111
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what It means if you don't override equals()
 
Similar Threads
A question about equals() method
Hash Map question ...
Doubt related to HashMap
why am i getting a null value on fetching from map
hashtable working & overriding equals