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

Inference chokes on wildcard derived from method reference

XMLWordPrintable

    • b42
    • Verified

        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?

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

                Created:
                Updated:
                Resolved: