aspose file tools
The moose likes Beginning Java and the fly likes == Vs .equals() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "== Vs .equals()" Watch "== Vs .equals()" New topic
Author

== Vs .equals()

Clarence J M Tauro
Ranch Hand

Joined: Aug 09, 2008
Posts: 30
Consider the following code



Is it the same, considering that the Object class's .equals() method being invoked?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3026
    
    4

That depends on the runtime type of a.


Steve
Clarence J M Tauro
Ranch Hand

Joined: Aug 09, 2008
Posts: 30
Ha ha, Nice way to answer. Thanks a lot..
Anirudh Aithal
Greenhorn

Joined: Jun 09, 2009
Posts: 7
I found a nice article about this:
http://www.ccnyddm.com/JavaBook/EqualsEtc.htm


Regards,
Anirudh
Raj chiru
Ranch Hand

Joined: Aug 12, 2008
Posts: 140
The default behaviour (default implementation) of equals() is to do == comparisions.
if you do't override the equals() in a class ,no two objects can ever be consider equal since references to two different objects will always contain a
different pattern (i.e hash value is different)
Chitta Ranjan Mahato
Ranch Hand

Joined: Jun 20, 2009
Posts: 38
Raj chiru
Ranch Hand

Joined: Aug 12, 2008
Posts: 140
In case of Wrapper classes it's true
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: == Vs .equals()
 
Similar Threads
how to override equals() method in java??
Which one is faster (before writing metric code)
JTextField/Reading Content
simple program - unable to remove ALL duplicates when comparing 2 different arrays
SAX + namespace