# Split Multiple Variable Declarations

# Properties

Property Value
Rule ID MultiVariableDeclarationLine
First seen in jSparrow version 2.0.0
Minimum Java version 1.1
Remediation cost 2 min

# Description

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.

# Benefits

Applying this rule makes the code easier to read.

# Code Changes

Pre

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;
}

Post

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:

# Tags

1
default
You & jSparrow
default

Hey there! May I help you? 😊