Back to Intellij Community

CollectionsFieldAccessReplaceableByMethodCall

java/java-impl/resources/inspectionDescriptions/CollectionsFieldAccessReplaceableByMethodCall.html

2025.3-rc-2570 B
Original Source

Reports usages of java.util.Collections fields: EMPTY_LIST, EMPTY_MAP or EMPTY_SET. These field usages may be replaced with the following method calls: emptyList(), emptyMap(), or emptySet(). Such method calls prevent unchecked warnings by the compiler because the type parameters can be inferred.

Example:

List<Integer> emptyList = Collections.EMPTY_LIST;

After the quick-fix is applied:

List<Integer> emptyList = Collections.emptyList();

This inspection only reports if the language level of the project or module is 5 or higher.