Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
aslika bahini
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this link may help you!


Thanks,
 
aslika bahini
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic