Avoid negation in your ternary operation

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