Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Objects equal method

 
kish kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The description of Object class equal method says for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).



The above code displays true. o1 and o2 refer 2 different objects. inside equals method we have code "return this==obj" .when o1 and o2 refer different objects == should return false. but why i am getting true?

how the equals method of object different from equals method of String?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Integer class overrides the equals method.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how the equals method of object different from equals method of String?


Di you mean to say equals() method of Integer ?
 
kish kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

equlas method of object vs equlas method of string
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kish kumar wrote:
equlas method of object vs equlas method of string


I noticed that you are comparing Integers in your code snippet, which is why I asked.

This is the equals implementation of String



And this is the implementation for Object.java




And for Integer.java we have

 
kish kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic