This Integer.valueOf(int)
similar for Boolean, Byte, Character, Long, Float and Double.
Note: for booleans and bytes, all possible values ββare cached. For characters, values ββ0 through 127 are cached. For short and long values, -128 - 127 are cached. For Integer -128 - 127 are cached by default, but the maximum can be increased using several parameters.
This can lead to unexpected behavior with
System.out.println((Integer) (int) -128 == (Integer) (int) -128); System.out.println((Integer) (int) -129 == (Integer) (int) -129);
prints
true false
Not sure if you need to do -128
using (int) -128
to compile in Java 7.
source share