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

Potential compatibility should not substitute explicit type args

    XMLWordPrintable

Details

    Description

      Per JLS 8 15.12.2.1, all lambdas and method references are considered potentially compatible with bare type arguments. But when there are explicit type arguments, javac appears to be substituting away the bare type argument before performing this check. This is incorrect. (The analysis is intentionally simple, avoiding things like subtyping and substitutions.)

      public class ExplicitFunctionArg {

          interface Sink<T> { void test(T arg); }

          <T> void m(T arg, java.io.Serializable x) {}
          <T> void m(Sink<T> arg, Cloneable x) {}

          void test() {
              this.<String>m(x -> {}, new int[0]);
              // expected: ambiguity error; actual: no error
          }

      }

      Reported by Jon Rafkind at lambda-spec-observers@openjdk.java.net.

      Attachments

        Activity

          People

            dlsmith Dan Smith
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: