Since Checkstyle 5.0
Checks that method type parameter names conform to a specified pattern.
name | description | type | default value | since |
---|---|---|---|---|
format | Specifies valid identifiers. | Pattern | "^[A-Z]$" |
5.0 |
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="MethodTypeParameterName"/> </module> </module>
Code Example:
class MyClass { public <T> void method1() {} // OK public <a> void method2() {} // violation, name 'a' must match pattern '^[A-Z]$' public <K, V> void method3() {} // OK public <k, V> void method4() {} // violation, name 'k' must match pattern '^[A-Z]$' }
An example of how to configure the check for names that are only a single letter is:
<module name="Checker"> <module name="TreeWalker"> <module name="MethodTypeParameterName"> <property name="format" value="^[a-zA-Z]$"/> </module> </module> </module>
Code Example:
class MyClass { public <T> void method1() {} // OK public <a> void method2() {} // OK public <K, V> void method3() {} // OK public <k, V> void method4() {} // OK }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.naming