aspose file tools*
The moose likes Beginning Java and the fly likes == Vs .equals() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
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: 4179
    
  21

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: 141
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: 141
In case of Wrapper classes it's true
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: == Vs .equals()