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

Inference chokes on wildcard derived from method reference

    XMLWordPrintable

Details

    • b42
    • Verified

    Backports

      Description

        This will not compile:

            void test(Box<? extends Box<? extends Number>> b) {
                Number n = b.map(Box::get).get();
            }

            interface Func<S,T> { T apply(S arg); }

            interface Box<T> {
                T get();
                <R> Box<R> map(Func<T,R> f);
            }

        error: incompatible types: inferred type does not conform to upper bound(s)
                Number n = b.map(Box::get).get();
                                ^
            inferred: ? extends Number
            upper bound(s): Object

        If I remove the wildcards, there is no error.

        Perhaps javac is failing to capture the return type of Box.get?

        Attachments

          Issue Links

            Activity

              People

                vromero Vicente Arturo Romero Zaldivar
                dlsmith Dan Smith
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: