Files
openide/java/java-impl/resources/inspectionDescriptions/ForEachWithRecordPatternCanBeUsed.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

38 lines
1.3 KiB
HTML

<html>
<body>
Reports local variable declarations and accessors to record components that can be replaced with pattern variables in enhanced `for` statements, which are usually more compact.
<p><b>Example:</b></p>
<pre><code>
record Record(Integer x, String y) {
}
public static void test(List&lt;Record&gt; records) {
for (Record record : records) {
System.out.println(record.y());
Integer x = record.x;
System.out.println(x);
}
}
</code></pre>
<p>Can be replaced with:</p>
<pre><code>
record Record(Integer x, String y) {
}
public static void test(List&lt;Record&gt; records) {
for (Record(Integer x, String y) : records) {
System.out.println(y);
System.out.println(x);
}
}
</code></pre>
<!-- tooltip end -->
<ul>
<li>Use the <b>Nesting depth limit</b> option to specify the maximum number of nested deconstruction patterns to report</li>
<li>Use the <b>Maximum number of record components to deconstruct</b> option to specify the maximum number of components, which a record can contain to be used in deconstruction patterns</li>
<li>Use the <b>Maximum number of not-used record components</b> option to specify the maximum number of components, which are not used in <code>for</code> statement</li>
</ul>
<p><small>New in 2023.1</small></p>
</body>
</html>