When we use '=' to compare the basic type, the value is compared.
However, when the = Operator is used to compare the wrapper object, it is used to check whether the object value is directed to the same storage region. Therefore, the following comparison is generally not true:
Integer A = 1000; integer B = 1000; if (a = B )...
But Java implementation may make it true: (Change 1000 to 100)
Integer A = 100; integer B = 100; if (a = B )...
Why?
It turns out that the automatic packaging operation is involved here, and the int type is automatically packaged into an integer type. WhileThe automatic packaging specification must be boolean, byte, char <= 127, ranging from-128 ~ The short and INT values between 127 are encapsulated into a fixed object, that is, the same memory area..
To avoid this problem, we recommend that you use the equals method to compare whether objects are equal, instead of using the = Operator to compare whether objects are the same.