• Post Reply Bookmark Topic Watch Topic
  • New Topic

wondering about equals() method  RSS feed

 
Lucky Lam
Greenhorn
Posts: 10
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm new to Java, May I ask why things happend that way? Thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you haven't over ridden the equals method in Value, the call is delegated to the super class (in this case Object)
From the API docs for Object#equals()
The equals method for class Object implements the most discriminating possible equivalence relation
on objects; that is, 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).

Since v1 and v2 do not refer to the same object, it evaluates to false

To see this in action, try the following code.
 
Lucky Lam
Greenhorn
Posts: 10
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand now thanks so much
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!