Final means " This value cannot be changed ".
When the final modified variable:
The final variable can be assigned directly, can be declared, then assigned, or it can point to a reference, but once you point to a reference, you cannot change to another reference.
- Used to modify data, including member variables and local variables, which can only be assigned once and whose values cannot be changed. For a member variable, we must assign a value to it either at declaration time or in the constructor method;
- Used to modify a method parameter to indicate that its value cannot be changed during the lifetime of the variable;
- A modification method that indicates that the method cannot be overridden;
- Modifies the class to indicate that the class cannot be inherited.
Of the four methods above, the third and fourth methods need to be used with caution, because in most cases we do not need to use final to decorate methods and classes, if only for the sake of design considerations.
The final discussion of Java learning