mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-07 07:55:31 +07:00
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
31 lines
1.5 KiB
HTML
31 lines
1.5 KiB
HTML
<html>
|
|
<body>
|
|
Reports <code>for</code> loops that iterate over collections or arrays,
|
|
and can be automatically replaced with an enhanced <code>for</code> loop (foreach iteration syntax).
|
|
<!-- 'foreach' still used in this description so that the inspection continues to be found using this keyword -->
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
for (Iterator<String> iterator = list.iterator(); iterator.hasNext(); ) {
|
|
String item = iterator.next();
|
|
System.out.println(item);
|
|
}
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
for (String item : list) {
|
|
System.out.println(item);
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p>
|
|
Use the <b>Report indexed 'java.util.List' loops</b> option to find loops involving <code>list.get(index)</code> calls.
|
|
Generally, these loops can be replaced with enhanced <code>for</code> loops,
|
|
unless they modify an underlying list in the process, for example, by calling <code>list.remove(index)</code>.
|
|
If the latter is the case, the enhanced <code>for</code> loop may throw <code>ConcurrentModificationException</code>.
|
|
Also, in some cases, <code>list.get(index)</code> loops may work a little bit faster.</p>
|
|
<p>
|
|
Use the <b>Do not report iterations over untyped collections</b> option to ignore collections without type parameters.
|
|
This prevents the creation of enhanced <code>for</code> loop variables of the <code>java.lang.Object</code> type and the insertion of casts
|
|
where the loop variable is used.</p>
|
|
</body>
|
|
</html> |