Wed 10 Aug 2016 03:15:45 PM UTC, comment #2:
Yes, first sentence is correct.
Second one I wonder because I read:
ublic static Integer valueOf(int i)
Returns an Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values. This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range.
Parameters:
i - an int value.
Returns:
an Integer instance representing i.
Since:
1.5
meaning that numbers in range -127,128 are cached always,
i.e. never lead to object creation when invoked in that range.
The should sentence means that normally,
a new object is created only if an equivalent one is not yet cached.
See also
http://stackoverflow.com/questions/2974561/new-integer-vs-valueof
on boxing with reference to jls specification.
There explicitly equality of two integers means that they are the same.
Normally, valueOf is what is used for boxing/unboxing.
By the way, here we see, that we shall not talk about boxing
when we just mean conversion java-octave.
|