• 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

if we override hashCode method is compulsary to override equals method and viseversa.

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if we override hashCode method is compulsary to override equals method and viseversa.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as far as I know if you override the equals method you must override the hashCode method. This is because the hashCode method must return equal hashCodes for objects that are equal according to the equals method. But the default implementation of hashCode method in Object class considers the memory location of the object into calculating hashCode so if you return true from your equals method the hashCode method from the Object class might return unequal hashCodes.

However if you override the hashCode method then you may choose not to implement the equals method. This is because the equals method implementation in the Object class just checks for reference equality. Adding to this hashCode method can return same hashCode for objects that are unequal according to the equals method....

My language is pretty technical but I hope you will get it....Also please correct me if I am wrong.....Thanks...
 
varinder mahajan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ankit , I got it
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic