mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
27 lines
1.1 KiB
HTML
27 lines
1.1 KiB
HTML
<html>
|
|
<body>
|
|
Reports calls to <code>Arrays.asList()</code> with at most one argument.
|
|
<p>
|
|
Such calls could be replaced
|
|
with <code>Collections.singletonList()</code>, <code>Collections.emptyList()</code>,
|
|
or <code>List.of()</code> on JDK 9 and later, which will save some memory.</p>
|
|
<p>In particular, <code>Collections.emptyList()</code> and <code>List.of()</code> with no arguments
|
|
always return a shared instance,
|
|
while <code>Arrays.asList()</code> with no arguments creates a new object every time it's called.</p>
|
|
<p>Note: the lists returned by <code>Collections.singletonList()</code> and <code>List.of()</code> are immutable,
|
|
while the list returned <code>Arrays.asList()</code> allows calling the <code>set()</code> method.
|
|
This may break the code in rare cases.</p>
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
List<String> empty = Arrays.asList();
|
|
List<String> one = Arrays.asList("one");
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
List<String> empty = Collections.emptyList();
|
|
List<String> one = Collections.singletonList("one");
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p>
|
|
</body>
|
|
</html> |