I've never done much research on these two rules of comparison, the confused know how to compare, also has not made mistakes, a moment to make dizzy, whistling, suddenly like research,
Simply:
= = is a comparison of two object addresses, focusing on the comparison of value objects, the comparison of values with equals comparison value Reference object its comparison results must be correct, but not recommended to use, appear irregular bar
The actual value reference is stored in the stack, each value is unique in the stack, the address in the stack is unique, the comparison is the address value, so if the value of two or more reference objects is the same, it points to the stack of the
The value address must be the same
According to the continuation analysis above, equals is the same as the content stored in the stack of two or more objects compared, not the same as the stack address, each class object will have a comparison of the Equals method, but there is an override for equals in the String class. So focusing on the equals of the string object, it's important to note
Drawing a schematic reference, look at the following example:
Qus result
I1==i2 false
I1.equals (I2) True
I2==i3 false
I2.equals (i3) False
I3 ==i4 True
I3.equals (I4) false
Thank you for reading, if there are errors please criticize correct, I will be open-minded to accept, learn from each other!!!
Thanks again!!!
talking about = = and equals