Inspectopedia Help

'Optional' contains array or collection

Reports java.util.Optional or types with an array or collection type parameter.

In such cases, it is more clear to just use an empty array or collection to indicate the absence of result.


Optional<List<Integer>> foo() { return Optional.empty(); }

This code could look like:

List<Integer> foo() { return new List<>(); }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3


Java, 233.SNAPSHOT

Last modified: 13 July 2023