Back to Intellij Community

ChainedEquality

java/java-impl/resources/inspectionDescriptions/ChainedEquality.html

2025.3-rc-2427 B
Original Source

Reports chained equality comparisons.

Such comparisons may be confusing: a == b == c means (a == b) == c, but possibly a == b && a == c is intended.

Example:

boolean chainedEquality(boolean a, boolean b, boolean c) {
    return a == b == c;
  }

You can use parentheses to make the comparison less confusing:

boolean chainedEquality(boolean a, boolean b, boolean c) {
    return (a == b) == c;
  }