# 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
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;
}
🛠️ Auto-refactor Available
You can auto-refactor this with jSparrow.
Drop this button to your Eclipse IDE workspace to install jSparrow for free:
Need help? Check out our installation guide.
# Properties
Property | Value |
---|---|
Rule ID | MultiVariableDeclarationLine |
First seen in jSparrow version | 2.0.0 |
Minimum Java version | 1.1 |
Remediation cost | 2 min |