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

add missing wildcards to Optional or() and flatMap()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 9
    • None
    • core-libs
    • b142

    Description

      In Optional, the signature of flatMap() should be changed as follows:

      OLD: <U> Optional<U> flatMap(Function<? super T, Optional<U>> mapper)
      NEW: <U> Optional<U> flatMap(Function<? super T, Optional<? extends U>> mapper)

      The signature of or() should be changed as follows:

      OLD: Optional<T> or(Supplier<Optional<T>> supplier)
      NEW: Optional<T> or(Supplier<Optional<? extends T>> supplier)

      This will alleviate some restrictions on the mapper and supplier functions.

      Some compatibility analysis should be done on flatMap() because it was originally defined in Java 8. The or() method is new in Java 9 so there should be no compatibility impact.

      Attachments

        Issue Links

          Activity

            People

              smarks Stuart Marks
              smarks Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: