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

A question about equals() method

 
avseq anthoy
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!everyone.
I see Sun Certified Programmer for Java 2 Study Guide and it says that if you want objects of your class to be used as keys for a hashtable then you must override equals().But why I can put a class defined by myself into HashTable?

why the following sample has overridden equals() and hashcode() but printed "test null" rather than "test test"?

 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The C in hashCode should be upper case. You have used lower case characters, so you really did not override the hashCode method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic