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:40 AM
Member
 
Join Date: May 2008
Posts: 3
skyineyes is on a distinguished road
Object class's equals() method behavior????
Hi

Can anybody comment on my observation ???

equal() method of object class will return true IFF

a) Both references are same?
b) Will return false even if the data is same but references are different?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-26-2008, 01:41 PM
Member
 
Join Date: May 2008
Posts: 3
skyineyes is on a distinguished road
The equals() method in the class Object uses only the == operator for comparisons so unless you override equals(), two objects are considered equal only if the two references refer to the same object.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-26-2008, 06:25 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:
unless you override equals(), two objects are considered equal only if the two references refer to the same object.
What do you mean?
If i override the equals() method, i can only get a "true" if both references are only in the same object?

If it is, it depends on the new implementation....
__________________
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
  #4 (permalink)  
Old 05-27-2008, 12:13 PM
M77's Avatar
M77 M77 is offline
Member
 
Join Date: May 2008
Location: LV
Posts: 36
M77 is on a distinguished road
Send a message via Skype™ to M77
Equals is ok method. Why it belongs to Object class it's a question. You may need to check if 2 objects equals by content and not by references.
__________________

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
  #5 (permalink)  
Old 07-20-2008, 01:58 AM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Hello skyineyes
Quote:
Originally Posted by skyineyes View Post
Hi

Can anybody comment on my observation ???

equal() method of object class will return true IFF

a) Both references are same?
b) Will return false even if the data is same but references are different?
Consider the variables A and B:
Code:
A.equals(B) is true if and only if A and B references the same object.
Mostly, we want to see if two objects are equal by value and not by reference. So then, we override the equals() method. In your question, both a and b are true.
__________________
If your ship has not come in yet then build a lighthouse.
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
Why Equals method should be over ridden in Hashcode? skyineyes New To Java 1 05-26-2008 06:13 PM
Calling a method for all instances of an object rattle New To Java 4 04-30-2008 04:10 PM
[SOLVED] If a object equals another object, do they contain the same data? bobleny New To Java 1 04-18-2008 12:10 AM
Object from String (calling method dynamically) Java Tip Java Tips 0 02-16-2008 11:22 PM
name clash: equals(E) in and equals(java.lang.Object) AdRock New To Java 0 01-26-2008 01:13 AM


All times are GMT +3. The time now is 03:32 PM.


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