Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-26-2008, 11:26 AM
Member
 
Join Date: May 2008
Posts: 3
skyineyes is on a distinguished road
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 ?

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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-26-2008, 06:13 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Quote:
I am not understanding that why Equals method needs to be overridden for use in Hashcode ?
Who asked you about that?

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....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot call private method from static method jon80 New To Java 3 05-07-2008 10:37 AM
[SOLVED] If a object equals another object, do they contain the same data? bobleny New To Java 1 04-18-2008 12:10 AM
name clash: equals(E) in and equals(java.lang.Object) AdRock New To Java 0 01-26-2008 01:13 AM
method not abstract, does not override actionperformed method. Theman New To Java 1 05-08-2007 08:13 AM


All times are GMT +3. The time now is 07:10 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org