mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
39 lines
1.4 KiB
HTML
39 lines
1.4 KiB
HTML
<html>
|
|
<body>
|
|
Reports assignment to, or modification of a <code>for</code> loop parameter inside the body of the loop.
|
|
<p>Although occasionally intended, this construct may be confusing and is often the result of a typo or a wrong variable being used.</p>
|
|
<p>The quick-fix adds a declaration of a new variable.</p>
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
for (String s : list) {
|
|
// Warning: s is changed inside the loop
|
|
s = s.trim();
|
|
System.out.println("String: " + s);
|
|
}
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
for (String s : list) {
|
|
String trimmed = s.trim();
|
|
System.out.println("String: " + trimmed);
|
|
}
|
|
</code></pre>
|
|
<p>Assignments in basic <code>for</code> loops without an update statement are not reported.
|
|
In such cases the assignment is probably intended and can't be easily moved to the update part of the <code>for</code> loop.</p>
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
for (int i = 0; i < list.size(); ) {
|
|
if (element.equals(list.get(i))) {
|
|
list.remove(i);
|
|
} else {
|
|
// modification of for loop parameter is not reported
|
|
// as there's no update statement
|
|
i++;
|
|
}
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p>Use the <b>Check enhanced 'for' loop parameters</b> option to specify whether modifications of enhanced <code>for</code> loop parameters
|
|
should be also reported.</p>
|
|
</body>
|
|
</html> |