Final variables need to use
Abstract: The final variables need to use
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="271" height="86" align="center" valign="top"> </ td> <td width="413" valign="top">
The final variable in the java, java compiler is optimized for the. Each of the final use of the types of local variables are not connected through the visit. For example, the use of the Test Data category of a final figure fNumber int = 77, this time, java compiler 77 will be compiled into Test this constant kind of scripting or constant pool. In this way, each class used fNumber Test when not connected to the Data cited by category to read, but used directly in the preservation of their own copies of documents.
Use procedures words:
Test.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;
)
Executive orders and results:
C: \> javac Test.java
C: \> java Test
77
This time, we change Data.java contents:
(Public class Data
Public static final int fNumber = 777;
)
Then run the following commands:
C: \> javac Data.java
C: \> java Test
77
C: \>
Here, we see that, although the Data.java fNumber has changed to 777, and has been recompiled, but because the compiler to save a copy of Test fNumber category, in the category of recompiled Test, the Test category has been fNumber think it is 77 rather than 777. Below we variation Test.java further implementation, look at the results.
C: \> javac Test.java
C: \> java Test
777
This time, we see that the Test recompiled category will be the new 777 package to their numerical category.
The whole process is as follows:
C: \> javac Test.java
C: \> java Test
77
/ / Here has changed the content of Data.java
C: \> javac Data.java
C: \> java Test
77
C: \> javac Test.java
C: \> java Test
777
↑ Back
Tags: java environment variables, java final






