Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8201606

(opt) add Optional.isEmpty

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 11
    • 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

      /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() {
      
      

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

              Created:
              Updated:
              Resolved: