...
| Code Block | ||
|---|---|---|
| ||
public class Foo {
static private final int MAX_COUNT;
public void counter() {
int count = 0;
while (condition()) {
/* ... */
if (count++ > MAX_COUNT) return;
}
}
/* No other method references count */
/* but several other methods reference MAX_COUNT */
}
|
Applicability
Do not use a larger scope than necessary because it will result in less reliable code.
Detecting local variables that are declared in a larger scope than is required by the code as written is straightforward and can eliminate the possibility of false positives.
...