Results 1 to 2 of 2
- 05-26-2008, 09:26 AM #1Member
- Join Date
- May 2008
- Rep Power
Why Equals method should be over ridden in Hashcode?
I am not understanding that why Equals method needs to be overridden for use in Hashcode ?:confused: :mad::confused:
Can anybody give a very very basic code example to make it clear...
a) example not using overridden equals method ... with dis-advantage
b) example using overridden equals method and hashcode method
- 05-26-2008, 04:13 PM #2I am not understanding that why Equals method needs to be overridden for use in Hashcode ?
reimplementing it through hascode is like,
Get the hashcode for the String1 to be compared (an int)
Get the hashcode for the String2 (will be compared) (an int)...
equate them, if they are equal, then return true, otherwise false.
The advantage is that, whenever they came from different instances, they could still be compared.
Try to browse the code for equals method(under the class that will be overriden) and see how it is implemented....
you can find it in (im not sure) it's a zip file named src that can be found in jdk folder.
....Just to eliminate confusions....freedom exists in the world of ideas
- By Theman in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:12 PM
- By jon80 in forum New To JavaReplies: 3Last Post: 05-07-2008, 08:37 AM
- By bobleny in forum New To JavaReplies: 1Last Post: 04-17-2008, 10:10 PM
- By AdRock in forum New To JavaReplies: 0Last Post: 01-25-2008, 11:13 PM