References in Java

Source: Internet
Author: User

Each typeProgramming LanguageThey all have their own ways to manipulate elements in the memory. SometimesProgramYou must note the type of data to be processed. Are you directly manipulating elements or using some indirect representation based on special syntaxes (for example, pointers in C and C ++) to manipulate objects.

All of this in Java is simplified. Everything is regarded as an object, so a single fixed syntax can be used. Although everything is regarded as an object, the operated identifier is actually a reference of the object ). You can use the reference view as the remote control and the object as the TV. You only need to hold the remote control to maintain the connection with the TV. When someone wants to change the channel, the actual control is the remote control (reference), and then the remote control controls the TV (object ).

In addition, even if there is no TV, the remote control can exist independently. That is to say, if you have a reference, you do not need to associate an object with it. For example, if you want to manipulate a word or sentence, you can create a string reference.

String S;

Here, only references are created, not objects. If a message is sent to s at this time, a runtime error is returned. This is because s is not actually associated with anything (that is, no TV set ). Therefore, a secure approach is to create a reference and initialize it at the same time.

String S = "ASDF ";

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.