Forums Register Login

K & B: Collections Self-Test Question

+Pie Number of slices to send: Send
Hi,

Here is the question on Page 630 & Question #12 ,



The code doesn't compile and it is fine, but if I change the code to,



And changing Person's class to



then the answer is A,B,C,E but I thought it should be A,B,C,D since Person overrides equals() and hashcode() and mutually comparable then how come duplicates are added to Set. Am I missing something here? Thanks.
+Pie Number of slices to send: Send
I admit I puzzled over this for awhile until I spotted the error.

Note that in your definition of Person, you have the method hashcode().

However, the method you need to override from Object is hashCode().
+Pie Number of slices to send: Send
Oops...good caught. I never realized it's a typo error.

[B][/B]ofcourse

Anyway its a good lesson to prepare for test.
+Pie Number of slices to send: Send
This had me a bit boggled as well, nice catch on that Keith.
+Pie Number of slices to send: Send
Hi ranchers,


annotations are not on the exam. But use it!

@Override

above your methods, and the compiler would shout out loud.

eg



will not compile, because one method is called em-two-el and the other m-twentyone.


Yours,
Bu.
[ October 28, 2006: Message edited by: Burkhard Hassel ]
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 855 times.
Similar Threads
A Generics and Collections Problem
Another Generics question
K&B Self Test Pg 617, Q12- HashSet doubt
what is the correct answer?
Generics K&B doubt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:33:54.