Summary
A new method isEmpty which would return true if the corresponding Optional does not have a value. Else, it would return false.
The proposed method is to be added in Optional, OptionalInt, OptionalDouble and OptionalLong classes.
Problem
A method isPresent is available now in Optional, OptionalInt, OptionalDouble and OptionalLong classes. It would be helpful to have its inverse Optional.isEmpty as well.
Solution
A new method isEmpty in Optional, OptionalInt, OptionalLong and OptionalDouble classes.
Specification
<pre> /src/java.base/share/classes/java/util/Optional.java /** + * If a value is not present, returns {@code true}, otherwise + * {@code false}. + * + * @return {@code true} if a value is not present, otherwise {@code false} + * @since 11 + */ + public boolean isEmpty() { /src/java.base/share/classes/java/util/OptionalDouble.java /** + * If a value is not present, returns {@code true}, otherwise + * {@code false}. + * + * @return {@code true} if a value is not present, otherwise {@code false} + * @since 11 + */ + public boolean isEmpty() { /src/java.base/share/classes/java/util/OptionalInt.java /** + * If a value is not present, returns {@code true}, otherwise + * {@code false}. + * + * @return {@code true} if a value is not present, otherwise {@code false} + * @since 11 + */ + public boolean isEmpty() { /src/java.base/share/classes/java/util/OptionalLong.java /** + * If a value is not present, returns {@code true}, otherwise + * {@code false}. + * + * @return {@code true} if a value is not present, otherwise {@code false} + * @since 11 + */ + public boolean isEmpty() { </pre>
- csr of
-
JDK-8184693 (opt) add Optional.isEmpty
-
- Resolved
-