LambdaParameterName

Since Checkstyle 8.11

Description

Checks lambda parameter names.

Properties

name description type default value since
format Sets the pattern to match valid identifiers. Pattern "^[a-z][a-zA-Z0-9]*$" 8.11

Examples

To configure the check:

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

Code Example:

class Example1 {
  Function<String, String> function1 = s -> s.toLowerCase();
  Function<String, String> function2 =
          S -> S.toLowerCase(); // violation
}
        

An example of how to configure the check for names that begin with a lower case letter, followed by letters is:

<module name="Checker">
  <module name="TreeWalker">
    <module name="LambdaParameterName">
      <property name="format" value="^[a-z]([a-zA-Z]+)*$"/>
    </module>
  </module>
</module>
        

Code Example:

class Example2 {
  Function<String, String> function1 = str -> str.toUpperCase().trim();
  Function<String, String> function2 = _s -> _s.trim(); // violation

  public boolean myMethod(String sentence) {
    return Stream.of(sentence.split(" "))
            .map(word -> word.trim())
            .anyMatch(Word -> "in".equals(Word)); // violation
  }
}
        

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