If ** == ** is used when comparing Integer (≠ int), there are ** combinations ** that return true for values from -127 to +128.
The place where Integer was compared with ** == ** suddenly returned false from a certain point.
There are mainly the following three types. Integer i1 = 16; Integer i2 = Integer.valueOf(16); Integer i3 = new Integer(16)
The above pattern 1 is auto-unboxed, and the compiled result is a process using the valueOf method as in 2. (1 and 2 are equivalent) Reference: [Java] Auto Boxing, Unboxing
Integer.valueOf () is a specification that returns the cache (sometimes the same instance) from -128 to +127 due to the specification in the normal setting. Reference: I read the source of Integer
I noticed if I set up a limit value test in the Unit test. I feel like there are many other things I can do.
It was a good notice because I didn't know the existence of the cache until this happened.
Recommended Posts