Results 1 to 2 of 2
- 05-26-2008, 09:26 AM #1
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
Why Equals method should be over ridden in Hashcode?
Hi
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 #2
Who asked you about that?I 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
Similar Threads
-
method not abstract, does not override actionperformed method.
By Theman in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:12 PM -
cannot call private method from static method
By jon80 in forum New To JavaReplies: 3Last Post: 05-07-2008, 08:37 AM -
[SOLVED] If a object equals another object, do they contain the same data?
By bobleny in forum New To JavaReplies: 1Last Post: 04-17-2008, 10:10 PM -
name clash: equals(E) in and equals(java.lang.Object)
By AdRock in forum New To JavaReplies: 0Last Post: 01-25-2008, 11:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks