You need to pay attention to the following issues when using the final keyword:
(Recommended tutorial: java introductory tutorial)
1. Classes modified by final cannot be inherited;
2. Methods modified by final cannot be overridden;
3. Variables modified by final cannot be changed. If Modifying the reference means that the reference is immutable and the content pointed to by the reference is variable;
4. The JVM will try to inline the method modified by final to improve operating efficiency;
5. Constants modified by final will be stored in the constant pool during the compilation phase;
(Video tutorial recommendation: java video tutorial)
Pair a final field in the constructor The writing and subsequent assignment of a reference to the constructed object to a reference variable cannot be reordered between these two operations.
The first read of a reference to an object containing a final field and the subsequent first read of the final field cannot be reordered between the two operations.
The above is the detailed content of What should you pay attention to when using the final keyword?. For more information, please follow other related articles on the PHP Chinese website!