...
Code Block | ||
---|---|---|
| ||
public void f(boolean a, boolean b) { if (a == b) { /* ... */ } } |
Compliant Solution
When the assignment is intended, the following compliant solution clarifies the programmer's intent:
Code Block | ||
---|---|---|
| ||
public void f(boolean a, boolean b) { if ((a = b) == true) { /* ... */ } } |
Compliant Solution
Nevertheless, it may be preferable to express this same logic as an assignment followed by a conditional:
...
Again, this is frequently a case of the programmer mistakenly using the assignment operator =
instead of the equals operator ==
.
Compliant Solution
When the assignment of b
to a
is unintended, this conditional block is now executed when a
is equal to b
.
...