Java: final keyword, javafinal keyword
Release date:
Final keywords:
- Final: It is equivalent to making the modified variables, methods, or classes "fixed, finalized", so that the modified variables, methods, and classes cannot be changed again [override of inheritance can be restricted ].
- Final can modify classes, methods, and variables.
- Final-modified classes cannot be inherited.
- The final modifier method cannot be overwritten)
- The final modifier variable is a constant. The final modifier variable must be explicitly initialized and can only be initialized once. [Initialization can be directly declared and assigned values, or assigned values in the initialization code block or constructor, or passing parameters]
- Final cannot coexist with abstract interface, because the class modified by final cannot be inherited or overwritten.
- Final modifier reference variable: Internal data can be modified, but the object to which the object is pointed cannot be modified.
Supplement:
Internal class if you want to use local variables,Only local variables modified by final can be accessed:
The lifecycle of a local variable is different from that of an internal class. When a local variable is modified by final, the variable modified by final becomes a data member in the internal class.
(Java adopts a copy local variable (copy local variables) method. That is to say, the local variables defined as final can be copied and used, and the referenced variables can also be used, you cannot assign a value again. This leads to the illusion that you can access local variable (access to local variables). In this case, because you cannot re-assign values, unexpected events will not occur.)