Assignments within sub-expressions are hard to spot and therefore make the code less readable. Ideally, sub-expressions should not have side-effects.

Noncompliant Code Example

if ((str = cont.substring(pos1, pos2)) != '') { // Noncompliant
  //...
}

Compliant Solution

str = cont.substring(pos1, pos2);
if (str != '') {
  //...
}

Exceptions

Assignments in while statement conditions, and assignments enclosed in relational expressions are allowed.

while ((line = nextLine()) != null) {...} // Compliant

while (line = nextLine()) {...} // Compliant

if (line = nextLine()) {...} // Noncompliant

See