...
The use of the assignment operator in controlling conditional expressions frequently indicates programmer error and can result in unexpected behavior.
Exceptionally, it is permitted to use the assignment operator in conditional expressions if the expression assignment is not the controlling expression, as shown in the following compliant example: (That is, the assignment is a sub-expression.)
Code Block | ||
---|---|---|
| ||
String line; BufferedReader reader = // initialize while ((line = reader.readLine()) != null) { // ... work with line } |
...