File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashSet not using overridden equals method

 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with regards to this problem, I have discovered that HashSet.contains( Object o ) is not calling my .equals( Object o ) method that I've written for it. Is there any scenario in which HashSet.contains( Object obj ) would not invoke the obj.equals( hashset_element ) ?
Jamie
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually, now that I think of it, could my hashCode() method implementations be incorrect so they aren't checking in the right bucket for the element?
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jamie Robertson:
actually, now that I think of it, could my hashCode() method implementations be incorrect so they aren't checking in the right bucket for the element?

FOUND IT!!! damn hashCode() implementation all along. It was correct for checking equality within the same class, but when it tried to check equality with my second allowable class ( with its own different hashCode() implementation ) it couldn't find the right bucket to then check equality. One night of sleep, plus 6 minutes and problem solved!! it's too bad I don't get more sleep
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic