Java ==and equals deep understanding-written to java beginners

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.