Class FinalizeLocalVariablesVisitor<P>


  • @Incubating(since="7.0.0")
    public class FinalizeLocalVariablesVisitor<P>
    extends JavaIsoVisitor<P>
    FinalizeLocalVariables will add the "final" modifier keyword to local variables which are not being reassigned. A local variable is defined as being declared between the opening and closing braces of a method.

    (Note, this is not related to the "finalize" method provided by the root Object class. The "Finalize" in the name just refers to making a local variable "final".)

    For the time being, we keep the definition of "local variable" strictly to the technical definition of a variable declared between the opening and closing braces of a method. This means a method parameter variable will not be considered as a target for adding the "final" modifier; nor instance variables (non-static fields) nor class variables (static fields).

    See the official variables tutorial.

    There are specific situations which count as a "local variable". In fact, "local variable" has a specific technical definition, even though it is occasionally referred to when discussing other things (such as method parameter variables, or class variables ("static fields"), or instance variables ("non-static fields"), etc.). By the technical definition, a "local variable" is defined by the location it is declared.