Originally posted by James Quinton:
...what happens to integer value bigger than 127, say 1000? What is the underlying reason causing the difference (the book didn't say)? ...
According to
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.
...
Ideally, boxing a given primitive value p, would always yield an identical reference. In practice, this may not be feasible using existing implementation techniques. The rules above are a pragmatic compromise...
Maybe I'm wrong on this, but my interpretation is that there are no guarantees for values outside the byte range (-128 and 127).
Originally posted by James Quinton:
...what makes the difference? I assume valueOf() method only does the manual boxing for compiler, but looks like it does something else.
Integer's valueOf methods return a new instance of Integer, so there is no autoboxing in this example. Perhaps you're thinking of the parseInt method, which returns an int?