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

== and equals()

Vivek Alampally
Ranch Hand

Joined: Jul 10, 2008
Posts: 67
Hello,
Kindly explain what (& why) is going behind the scenes in the following program,


Output is

different objects
meaningfully equal
same object
meaningfully equal

Thanks
Vivek

Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
Please search the forums, there have been discussions on this topic before, infact with the same numbers.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

As Sridhar suggested, you will find this discussed by searching the forums.

The technical specification is under JLS - 5.1.7 Boxing Conversion...
If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: == and equals()