Why does the Hashcode of an Object change in Java? Does it change at all?
How is it related to Hashtable ?
Every object should have it’s unique hashcode.So, is Rehashing a reason for it ?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The default implementation of hashcode is equivalent to object identity. However, some objects override hashcode, which might give you a hashcode that changes based on object state.
Usually you do this if you’re overriding the definition of equals( in fact, if you override equals you should override hashcode). This is because you want objects that are equal by whatever definition you’ve created to return the same hashcode. Otherwise you can have a situation a map holds multiple “equal” objects, because they return different hashcodes.