File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

== Vs .equals()

 
Clarence J M Tauro
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following code



Is it the same, considering that the Object class's .equals() method being invoked?
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on the runtime type of a.

 
Clarence J M Tauro
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ha ha, Nice way to answer. Thanks a lot..
 
Anirudh Aithal
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a nice article about this:
http://www.ccnyddm.com/JavaBook/EqualsEtc.htm
 
Raj chiru
Ranch Hand
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Raj chiru
Ranch Hand
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case of Wrapper classes it's true
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic