• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HashSet not using overridden equals method

 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic