Today, to help people look at the code, find this problem, review it, record it.
Let's take a look at a code snippet
public static void Main (string[] args) {Integer a1 = integer.valueof; Danielinbiti Integer B1 =; System.out.println ("1:=" + (a1 = = B1)); Integer A2 =; Integer b2 =; System.out.println ("2:=" + (a2 = = b2)); Integer a3 = new Integer; Integer B3 =; System.out.println ("3:=" + (a3 = = B3)); Integer a4 = 129; Integer b4 = 129; System.out.println ("4:=" + (a4 = = b4)); }
The result of this code comparison, if not executed do not know what the answer is in your heart.
To know the answer, it involves the Java buffer and heap problems.
The number of integer types in Java is buffer-taken for numbers between 128-127, so the equals sign is consistent. But the number that is not in this interval is new in the heap. Therefore, the address space is not the same, it is not equal.
Integer b3=60, which is a boxing process that is also an integer b3=integer.valueof (60)
Therefore, it is necessary to use Intvalue () to see if the integer comparison value is equal.
There is no buffer for double.
Answer
1:=true
2:=true
3:=false
4:=false
An issue in Java where integer values are less noticeable