For the final variable in Java, the Java compiler is optimized. Every place that uses the final type variable is not accessed through a connection. For example, the test class uses a final int digit fnumber=77 in the data class, at which point the Java compiler compiles the 77 constant to the test class's instruction code or constant pool. This way, every time the test class uses fnumber, it is not connected to the data class by reference, but rather uses the copy that is saved in the class file directly.
To speak with a program:
C:\>javac Test.javaTest.java:
public class test{
public static void Main (string[] args) {
System.out.println (Data.fnumber);
}
}
Data.java:
public class data{
public static final int fnumber=77;
}
To execute commands and results:
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.