Avoid negation in your ternary operation

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-code-style/confusing-ternary

Language: Java

Severity: Notice

Category: Code Style

Description

Using a negative comparison in if expressions with an else clause can be confusing. Consider modifying your comparison by switching your if and else` block statements.

Non-Compliant Code Examples

public class Foo {
    String bar(int x, int y) {
        return (x != y) ? "diff" : "same";
    }
}

Compliant Code Examples

public class Foo {
    String bar(int x, int y) {
        return (x == y) ? "same" : "diff";
    }
}
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

PREVIEWING: mervebolat/span-id-preprocessing