Separate lines for each field declaration

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

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