Files
openide/java/java-impl/resources/inspectionDescriptions/DoubleBraceInitialization.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
1.1 KiB
HTML

<html>
<body>
Reports <a href="https://www.c2.com/cgi/wiki?DoubleBraceInitialization">Double Brace Initialization</a>.
<p>Compared to regular initialization, double brace initialization provides worse performance since it requires loading an
additional class.</p>
<p>It may also cause failure of <code>equals()</code> comparisons if the <code>equals()</code> method doesn't accept subclasses as
parameters.</p>
<p>Double brace initialization may cause memory leaks when used in a non-static context. This is because it defines an anonymous class
that will reference the surrounding object, when compiled with javac from before Java 18.</p>
<p>In addition, before Java 9, double brace initialization couldn't be combined with the diamond operator since it was incompatible
with anonymous classes.
</p>
<p><b>Example:</b></p>
<pre><code>
List&lt;Integer&gt; list = new ArrayList&lt;&gt;() {{
add(1);
add(2);
}};
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
list.add(1);
list.add(2);
</code></pre>
<!-- tooltip end -->
</body>
</html>