java.util.Collections unmodifiable collection calls,
that can be converted to newer collection factory methods.
These can be replaced with e.g. List.of() or Set.of() introduced in Java 9,
or List.copyOf() introduced in Java 10.
Note that, in contrast to java.util.Collections methods, the Java 9 collection factory methods
null values
null arguments to query methods like List.contains() or Map.get() of the collections returned.
Example:
List<Integer> even = Collections.unmodifiableList(
Arrays.asList(2, 4, 6, 8, 10, 2));
List<Integer> evenCopy = Collections.unmodifiableList(
new ArrayList<>(list1));
After the quick fix is applied the result looks like:
List<Integer> even = List.of(2, 4, 6, 8, 10, 2);
List<Integer> evenCopy = List.copyOf(list);
This inspection only reports if the configured language level is 9 or higher.
Use the first checkbox below to only report if the supplied arguments are compile-time constants.
This reduces the chance of changes in behaviour,
because it's not always possible to statically check whether original elements are unique and not null.
Use the second checkbox to suggest a Map.ofEntries() replacement for unmodifiable maps with more than 10 entries.
New in 2017.2