Inspectopedia Help

Reference to empty collection field can be replaced with method call

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();

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

CollectionsFieldAccessReplaceableByMethodCall
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Java language level migration aids | Java 5

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

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024