| Author |
Issue in Working with Maps
|
Maheswaran Devaraj
Ranch Hand
Joined: Sep 14, 2007
Posts: 47
|
|
Hi friends,
In the above code the marked line 7 also giving the null, I don't know why it is giving null, because I have defined
both the hashcode and equlas method in the Dog class.
Thanks in Advance,
Mahes
|
 |
Harshit Rastogi
Ranch Hand
Joined: Apr 15, 2008
Posts: 131
|
|
|
The culprit here is line 52, in which you are changing the name of d1 object. So when you try to retrieve from map the hashcode method will return different value since the name is changed and hence desired object will not be found.
|
<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
|
 |
arulk pillai
Author
Ranch Hand
Joined: May 31, 2007
Posts: 3190
|
|
|
It is a best practice to use immutable obejcts as your key. You can use the Wrapper classes.
|
Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
|
 |
 |
|
|
subject: Issue in Working with Maps
|
|
|