Add Optional.orNull() as convenience alternative to orElse(null)

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: None
    • Component/s: core-libs

      A DESCRIPTION OF THE PROBLEM :
      Introduce a convenience method T Optional.orNull() as a more readable alternative to repetitive Optional.orElse(null) calls.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      When interoperating with APIs that accept or require null, developers frequently write:

      Optional.orElse(null)

      Add the following method to java.util.Optional:

      /**
       * Returns the value if present, otherwise returns {@code null}.
       *
       * <p>This is a convenience method equivalent to {@code orElse(null)}.
       *
       * @return the contained value if present, otherwise {@code null}
       */
      public T orNull() {
          return value;
      }

      FREQUENCY :
      ALWAYS

            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: