Java final data and javafinal data

Source: Internet
Author: User

Java final data and javafinal data

Many programming languages have their own solutions to tell the compiler that a piece of data is a constant ". Constants are mainly used in the following two aspects:

1) The compile-time constant, which will never change;

2) A value initialized during running, we do not want it to change. Ss

For constants in the compilation period, the compiler (Program) can "encapsulate" the constant values into the required computing process. That is to say, the computation can be executed in advance during compilation, thus saving some runtime expenses. In Java, constants of these forms must belong to the basic data type (Primitives) and must be expressed using the final keyword.

Either the static or final fields can store only one data and cannot be changed.

If final is used along with the object handle, rather than the basic data type, its meaning is a bit confusing. For the basic data type, final converts the value to a constant, but for the object handle, final converts the handle to a constant. During the declaration, the handle must be initialized to a specific object. In addition, the handle cannot be changed to another object. However, the object itself can be modified. Java does not provide any means to convert an object directly into a constant.

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.