Inspectopedia
 
2024.3

Reference to empty collection field can be replaced with method call

Warning
New
Last modified: 03 December 2024

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:

After the quick-fix is applied:

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