Assignments within sub-expressions are hard to spot and therefore make the code less readable.

It is also a common mistake to write = when == was meant.

Ideally, sub-expressions should not have side-effects.

Noncompliant Code Example

doSomething(i = 42);

Compliant Solution

i = 42;
doSomething(i);
// or
doSomething(i == 42);  // Perhaps in fact the comparison operator was expected

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