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

28 lines
744 B
HTML

<html>
<body>
Reports allocations of arrays with known lengths of zero when there is a constant for that in the class of the array's element type.
As zero-length arrays are immutable, you can save memory reusing the same array instance.
<p><b>Example:</b></p>
<pre><code>
class Item {
// Public zero-length array constant that can be reused
public static final Item[] EMPTY_ARRAY = new Item[0];
}
class EmptyNode {
Item[] getChildren() {
// Unnecessary zero-length array creation
return new Item[0];
}
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
class EmptyNode {
Item[] getChildren() {
return Item.EMPTY_ARRAY;
}
}
</code></pre>
<!-- tooltip end -->
</body>
</html>