Java pass-through value and pass-through reference

Source: Internet
Author: User

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

1, for the basic type of variable, Java is a copy of the value, the instant its own copy has changed, and will not change itself.

2, for all object-type variables, Java is a copy of the reference, that is, copy the pointer to the address, it passes the reference copy to its own address.

Eg: you want to Zhang San (Zhang San equivalent function) to open the warehouse, and check the Library of goods (warehouse equivalent address), it is necessary to create a new warehouse (and put the same goods) to Zhang San?

No need, you just have to copy the key (reference) to Zhang San, Zhang San will copy the key (reference copy, but the timeliness, function end, key destruction) Open the warehouse.

Note: The string type is also an object-type variable, so he must be a copy of the reference, except that string is an immutable class, making it no different to pass or pass a reference.

Java pass-through value and pass-through 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.