There is no difference between the two types of variables of the basic type. Why is it possible to compare variables of the reference type?
What about different results? Remember the pointer in C ++? This is a bit like deep copy and shortest copy.
The reference of an object in Java is a pointer, but the Java language itself does not provide any syntax for direct access to it.
Because when we use a variable of the reference type, we always operate on the object pointed to by this reference, and cannot change
It itself, even if this variable references another object, it can be understood as "regular reference ".
The reference variable stores the address of the object in the heap memory. This address is called "reference variable value ".
When the operator "=" is used to operate two referenced variables, it is to compare whether the values of referenced variables are equal. So even if
The values are identical. They are also two independent regions in the heap. Of course they are not equal. In this case, equals uses their values to indicate
Obtain the values of the two objects respectively, and then compare the two values.
To put it bluntly, let's assume that Zhang San and Li Si look very similar (almost identical, in order to convince you that this is true, I
Suppose they are a mom and have the same habits, pictures, hobbies, and clothes ...)
"=" Means to ask: Is Zhang San and Li Si the same person?
"Equals" is to ask: do Zhang San and Li Si look the same?
Beginners who pass by, do you understand? If you still don't understand it, blame Zhang San and Li Si for going...
If you really understand this, I would like to thank Michael Zhang and Mr. Li for learning about the big God of male. I want to find it for any tangle. Hi!
This article is from the "random community" blog