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

Missing capture for method reference in inference

    Details

      Description

      This should compile but fails in javac 8 b121:

        Stream<Optional<? extends U>> s = null;
        Stream<U> s2 = s.map(Optional::get);

      error: incompatible types: inference variable R has incompatible bounds
        Stream<Number> s2 = s.map(Optional::get);
                                 ^
          equality constraints: Number
          lower bounds: ? extends Number
        where R,T are type-variables:
          R extends Object declared in method <R>map(Function<? super T,? extends R>)
          T extends Object declared in interface Stream

      Looks like there's a failure to capture '? extends Number', as specified by JLS 15.13.1: "If the ReferenceType [Optional] is a raw type, and there exists a parameterization of this type, T, that is a supertype of P1 [Optional<? extends U>], the type to search is the result of capture conversion (5.1.10) applied to T"

        Attachments

          Activity

            People

            • Assignee:
              vromero Vicente Arturo Romero Zaldivar
              Reporter:
              dlsmith Dan Smith
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: