Split Multiple Variable Declarations


Property Value
First seen in jSparrow version 2.0.0
Minimum Java version 1.1
Remediation cost 2 min
Links S1659


Multiple field or variable declarations on the same line could cause confusion about their types and initial values. That also makes it harder to read and to understand the code.

In order to improve readability, each field or variable should be declared on a separate line.

This is recommended by the Code Conventions for the Java Programming Language.


Applying this rule makes the code easier to read.

Requirement & Tags



Code Changes


private int a, b;
@TestAnnotation List<Integer> list = new LinkedList<>(), list2;
list.stream().map(element -> {
        int x, y = -20;

        return element;
enum Foo {
    ASD, DFG;

    int a, b, c;


private int a;
private int b;
@TestAnnotation List<Integer> list = new LinkedList<>();
@TestAnnotation List<Integer> list2;
list.stream().map(element -> {
    int x;
    int y = -20;

    return element;
enum Foo {
    ASD, DFG;

    int a;
    int b;
    int c;

Automatic Application of This Rule

The automatic application of this rule is supported in the following jSparrow versions: