The alias mechanism in Java

Source: Internet
Author: User

Aliasing occurs primarily on assignment issues:
The assignment to the base data type is simple. The base data type stores the actual numeric value, not the reference to an object, so when you assign it, you copy the contents of one place directly to the other. For example, if you use a=b for the base data type, then B copies the contents of a. and b is not affected by this modification at all.
However, when the object is "assigned", the situation changes. When you manipulate an object, we actually manipulate the reference to the object. So if you "assign an object to another object", you actually copy the reference from one place to another. This means that if you use C=d for an object, Then both C and D point to the object that was originally directed to D.

Note the differences between the basic data types and objects in Java.

Such as:

In this, from N1=n2, N1 and N2 point to the same memory address, meaning that the memory address of the N1 is replaced by the N2 memory address, then, when modifying the value of N1, will also modify the value of N2, from. When you remove the ". I", you can see the memory changes

The alias mechanism in Java

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.