MethodTypeParameterName

Since Checkstyle 5.0

Description

Checks that method type parameter names conform to a specified pattern.

Properties

name description type default value since
format Sets the pattern to match valid identifiers. Pattern "^[A-Z]$" 5.0

Examples

To configure the check:

<module name="Checker">
  <module name="TreeWalker">
    <module name="MethodTypeParameterName"/>
  </module>
</module>
        

Code Example:

class Example1 {
  public <T> void method1() {}
  public <a> void method2() {} // violation
  public <K, V> void method3() {}
  public <k, V> void method4() {} // violation
}
        

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 Example2 {
  public <T> void method1() {}
  public <a> void method2() {}
  public <K, V> void method3() {}
  public <k, V> void method4() {}
}
        

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.naming

Parent Module

TreeWalker