(opt) add Optional.isEmpty

XMLWordPrintable

    • Type: CSR
    • Resolution: Approved
    • Priority: P3
    • 11
    • Component/s: core-libs
    • None
    • minimal
    • Java API
    • SE

      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>

            Assignee:
            Vivek Theeyarath (Inactive)
            Reporter:
            Stuart Marks
            Paul Sandoz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: