Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
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
bgColor#ccccff
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.

...