Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Autoboxing and == operator

 
Arkadiusz Przechodzki
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome,




Output: no yes

WTF?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Note that the above applies only to boxed values. Creating wrapper instances with "new" is different.

(Also, for the benefit of all users, please use real words instead of text abbreviations. Thanks!)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic