Nitesh Nandwana wrote:I know that every object has hashcode in integer form as a key to identify that object, and according to documentation of hashCode(), it returns hashCode value of invoking object.Now question is that in my program hashCode() is return the value of instance variable value of obj1 and obj2. those are 2 and 12. Where is the hashcode of objects ?? i am feeling very irritated because i don't want value of variable if i want variable value then simply i can make a get() method and return the variable value then why to use this nonsense hashCode(),I need hashcode please help me to find it
.
Nitesh Nandwana wrote:it gives hashCode value when i dont override hashCode() but it ought to override if equals() is overridden and why it gives different hashcode of two equal objects ?.
Eli Wood wrote: since every two equal InstEqual objects will have equal hashcodes.
Nitesh Nandwana wrote:In my last example, obj1 and obj2 are equal then why their hash code values are not same as you said above.
Nitesh Nandwana wrote:
Eli Wood wrote: since every two equal InstEqual objects will have equal hashcodes.
In my last example, obj1 and obj2 are equal then why their hash code values are not same as you said above.
Nitesh Nandwana wrote:
Eli Wood wrote: since every two equal InstEqual objects will have equal hashcodes.
In my last example, obj1 and obj2 are equal then why their hash code values are not same as you said above.
Eli Wood wrote:
Eli Wood wrote:
.
This code creates a new Integer using the "value" of this.value, calls the toString() method to return a string representation of the Integer, then calls the String class's hashCode() function(which overrides Object's hashCode() function) on that String to create a hash code.Nitesh Nandwana wrote:
Eli Wood wrote:
.
According to hashCode() documentation, it is invoked with object, here in above code how did you invoked and why did you so i am not getting at all.