Chained equality comparisons
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;
}
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023