MultipleVariableDeclarations

Since Checkstyle 3.4

Description

Checks that each variable declaration is in its own statement and on its own line.

Rationale: the Java code conventions chapter 6.1 recommends that declarations should be one per line/statement.

Examples

To configure the check:

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

Example:

public class Example1 {
  public void myTest() {
    int mid = 0;
    int high = 0;

    int lower, higher;
    // violation above, 'Each variable declaration must be in its own statement'

    int value, // violation, 'Each variable declaration must be in its own statement'
        index;
    int place = mid, number = high;
    // violation above, 'Each variable declaration must be in its own statement'
  }
}
        

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.coding

Parent Module

TreeWalker