You should also note that with autoboxing, equal values within the range of a byte will box to the same wrapper instance. Specifically, according to JLS - 5.1.7...
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
Joined: Jan 26, 2006
So based on:
"No, because they are both references, == is reference comparison. If one of the operands were a primitive int, the other would be unboxed before the comparison."
Wouldn't that mean that since they are both 2 they will point to the same reference variable making the == between them true?
Joined: Feb 07, 2005
No, what Marc is talking about is autoboxing.
In your code, you are creating two different objects.
Whenever you use the new operator, a new object is created.