Use Java to pass values and references, and use java to pass references

Source: Internet
Author: User

Use Java to pass values and references, and use java to pass references

In Java, variables are divided into the following two types,

1. for basic type variables, Java is a copy of the value, and its own copy changes instantly, and it will not change.

2. For all object-type variables, Java transmits a reference copy, that is, the copy pointer to the address, and the reference copy passed by it points to its own address.

Eg: Do you want Michael to open the warehouse and check the goods in the warehouse (the Warehouse is equivalent to the address)? Is it necessary to create a warehouse (and place the same goods) for Michael?

No. You just need to copy the key (reference) to Michael Jacob. Michael Jacob will open the warehouse with the copied key (reference the copy, but it is time-effective, the function ends, and the key is destroyed.

 

Note: The String type is also an object-type variable, so it must be a reference copy, but the String is an immutable class, which makes it no different to pass the value or reference.

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.