Normally, when the primitive types are boxed into the wrapper types, the JVM allocates memory and creates a new object. But for some special cases, the JVM reuses the same object.
The following is the list of primitives stored as immutable objects:
boolean values true and false
All byte values
short values between -128 and 127
int values between -128 and 127
char in the range \u0000 to \u007F
Originally posted by Shaily Sharma:
Does it mean range of an Integer is reduced in autoboxing process?
from 4 bytes to 1byte?
And why this results in immutable object?
as far as I cud recall the default Integer() object isnt
Originally posted by Ahmed Yehia:
Two Integers with the value between -128 and 127 are considered true comparing with == operator.