# Split Multiple Variable Declarations

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

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

Use a Java Refactoring Tool

Automate this Refactoring system-wide

You can apply this refactoring for free with the jSparrow Eclipse IDE plug-in.
Install the plug-in for Eclipse IDE: Eclipse Marketplace.

a drawn cute bird pointing at a graph that shows positive results

# Properties

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