This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue in Working with Maps

 
Maheswaran Devaraj
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
arulk pillai
Author
Ranch Hand
Posts: 3380
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a best practice to use immutable obejcts as your key. You can use the Wrapper classes.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic