mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
28 lines
1.1 KiB
HTML
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<Integer> list = new ArrayList<>() {{
|
|
add(1);
|
|
add(2);
|
|
}};
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
List<Integer> list = new ArrayList<>();
|
|
list.add(1);
|
|
list.add(2);
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
</body>
|
|
</html> |