From: http://www.iteye.com/topic/1116623
/* Hello. Java */
Import java. Lang. Integer;
Public class hello
{
Public static void main (string [] ARGs)
{
Int A = 1000, B = 1000;
System. Out. println (A = B );
Integer c = 1000, D = 1000;
System. Out. println (C = D );
Integer e = 100, F = 100;
System. Out. println (E = F );
}
}
Result:
True
False
True
Cause:
Integer type default-128 ~ 127 when cache data is used, the same object is used in the default range, so they are equal. Otherwise, they are not equal.
/**
* Returns a <tt> integer </tt> instance representing the specified
* <Tt> int </tt> value.
* If a new <tt> integer </tt> instance is not required, this method
* Shoshould generally be used in preference to the constructor
* {@ Link # INTEGER (INT)}, as this method is likely to yield
* Significantly better space and time performance by caching
* Frequently requested values.
*
* @ Param I an <code> int </code> value.
* @ Return a <tt> integer </tt> instance representing <tt> I </tt>.
* @ Since 1.5
*/
Public static integer valueof (int I ){
If (I >=- 128 & I <= integercache. High)
Return integercache. cache [I + 128];
Else
Return new INTEGER (I );
}