Separate lines for each field declaration

このページは日本語には対応しておりません。随時翻訳に取り組んでいます。翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください。

Metadata

ID: java-best-practices/one-declaration-per-line

Language: Java

Severity: Notice

Category: Best Practices

Description

In Java, it is possible to declare multiple variables of the same type on a single line using commas. This can make code more cluttered and less readable. Declare each variable on a separate line to improve code clarity and maintainability.

Non-Compliant Code Examples

public class Person {
    // combined declarations (same line) - a violation
    String firstName, lastName;

    // combined declaration (diff line) - no violation
    String firstName,
        lastName;
}

Compliant Code Examples

public class Person {
    // separate declarations - no violation
    String firstName;
    String lastName;     
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis