Use of final keywords

  1. Final can be used to modify the structure: classes, methods, variables

  2. final is used to modify a class: this class cannot be inherited by other classes. For example: String class, System class, StringBuffer class.

  3. final is used to decorate the method: this method cannot be overridden. For example: getClass() in the Object class.
    Extension: The method modified with the native keyword indicates that the method uses C/C++ code.

  4. Final is used to modify variables: the "variables" at this time become constants
    4.1 final modified attributes, the positions of assignment that can be considered are: display initialization, initialization in code blocks, initialization in the constructor
    4.2 final modification of local variables, especially the use of final When modifying a parameter, it indicates that the parameter is a constant, and only this parameter can be used in the method, and its value cannot be changed.

  5. Static final is used to modify attributes: global constants

Guess you like

Origin blog.csdn.net/AmorFati1996/article/details/108718546