Class FinalParametersCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public class FinalParametersCheck
    extends AbstractCheck
    Checks that parameters for methods, constructors, catch and for-each blocks are final. Interface, abstract, and native methods are not checked: the final keyword does not make sense for interface, abstract, and native method parameters as there is no code that could modify the parameter.

    Rationale: Changing the value of parameters during the execution of the method's algorithm can be confusing and should be avoided. A great way to let the Java compiler prevent this coding style is to declare parameters final.

    • Property ignorePrimitiveTypes - Ignore primitive types as parameters. Type is boolean. Default value is false.
    • Property ignoreUnnamedParameters - Ignore unnamed parameters. Type is boolean. Default value is true.
    • Property tokens - tokens to check Type is java.lang.String[]. Validation type is tokenSet. Default value is: METHOD_DEF, CTOR_DEF.

    Parent is com.puppycrawl.tools.checkstyle.TreeWalker

    Violation Message Keys:

    • final.parameter
    Since:
    3.0