The following results show how much code execution ()?
A.true,false,true
B.false,true,false
C.true,true,false
D.false,false,true
In fact, when we assigned to Integer, java compiler will translate into calls valueOf () method. For example Integer i = 127 is translated Integer i = Integer.valueOf (127)
Then we take a look at the source valueOf () function:
public static Integer valueOf(int i)
{
//high为127
if(i >= -128 && i <= IntegerCache.high)
return IntegerCache.cache[i + 128];
else
return new Integer(i);
}
As can be seen, for a number between -128 to 127, Java will be cached. And beyond that is to create a new object.
So now back to this problem Road
i1 and i2 128, out of range, so the need to create a new object, the object comparison is false;
100 i5 and i6, within range, when executed Integer i5 = 100, is cached in memory directly, but execution Integer i6 = 100, it is taken directly from the cache, without the need to create a new object, It is true.