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