Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hashCode( )

 
Maureen Charlton
Ranch Hand
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following output:

JOHN DOE : Java
Calculated hash=4 for JOHN DOE
students[hash]: JOHN DOE : Java
students hashCode value = 21990827

Could someone explain why I got the hashCode value = 21990827 and NOT 4? (4 is what I was expecting?



Do I need to have a toString( ) method? Similar to when I wish to have something more meaningful when printing out the contents of an array?

Thanking you in advance!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to override hashCode() in Student. If you wanted the hashCode() for a Student object to be the same as the hashCode() for the Student's name, then you could write

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic