• 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

equals and hashCode

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
In Cd-rom from book of Kathy Sierra and Bert Bates, the following question :



Which of the following will fulfill the equals() and the hashCode() contracts for this class?

Right Answer :



But in the second correct answer, if o.code.length()=2, o.bal=3, o.rate=4 and this.code.length()=2, this.bal=4, this.rate = 3. The two objects are equals but there hashCode() are different, so the contract is bad.
Could you explain me?

Thanks
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please have a look at this thread about something similar. It might in fact be about the same question!

Any more problems, please fire away
 
Cyril Boulm�
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have right, I continue on the other thread
 
reply
    Bookmark Topic Watch Topic
  • New Topic