mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
38 lines
1.7 KiB
HTML
38 lines
1.7 KiB
HTML
<html>
|
|
<body>
|
|
Reports <code>java.util.Collections</code> unmodifiable collection calls
|
|
that can be converted to newer collection factory methods.
|
|
These can be replaced with e.g. <code>List.of()</code> or <code>Set.of()</code> introduced in Java 9
|
|
or <code>List.copyOf()</code> introduced in Java 10.
|
|
|
|
<p>Note that in contrast to <code>java.util.Collections</code> methods, Java 9 collection factory methods:
|
|
<ul>
|
|
<li>Do not accept <code>null</code> values.
|
|
<li>Require unique set elements and map keys.
|
|
<li>Do not accept <code>null</code> arguments to query methods like <code>List.contains()</code> or <code>Map.get()</code> of the collections returned.
|
|
</ul>
|
|
<p>When these cases are violated, exceptions are thrown.
|
|
This can change the semantics of the code after the migration.</p>
|
|
<p>Example:
|
|
<pre><code>
|
|
List<Integer> even = Collections.unmodifiableList(
|
|
Arrays.asList(2, 4, 6, 8, 10, 2));
|
|
List<Integer> evenCopy = Collections.unmodifiableList(
|
|
new ArrayList<>(list1));
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
List<Integer> even = List.of(2, 4, 6, 8, 10, 2);
|
|
List<Integer> evenCopy = List.copyOf(list);
|
|
</code></pre>
|
|
|
|
<!-- tooltip end -->
|
|
<p>
|
|
Use the <b>Do not warn when content is non-constant</b> option to report only in cases when the supplied arguments are compile-time constants.
|
|
This reduces the chances that the behavior changes,
|
|
because it's not always possible to statically check whether original elements are unique and not <code>null</code>.
|
|
<p>
|
|
Use the <b>Suggest 'Map.ofEntries'</b> option to suggest replacing unmodifiable maps with more than 10 entries with <code>Map.ofEntries()</code>.
|
|
<p><small>New in 2017.2</small></p>
|
|
</body>
|
|
</html> |