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

Implement type variable renaming for functional interface most specific test

XMLWordPrintable

    • b102
    • Verified

      Per JDK-8042285, the JLS rules for functional interface comparison during most-specific testing failed to account for generic function types. This can be addressed in the same way as overriding: ensuring the two signatures have equivalent type parameters (same number, equivalent bounds), and then alpha-renaming from one to the other. (See JDK-8042285 comments for details.)

      javac does nothing with any type parameters in the signatures, and should be updated.

      interface F1 { <X> Object apply(X arg); }
      interface F2 { <Y> String apply(Y arg); }
      interface F3 { <X> Object apply(Object arg); }
      interface F4 { String apply(Object arg); }

      static void m1(F1 p) { System.out.println("F1"); }
      static void m1(F2 f) { System.out.println("F2"); }
      static void m2(F3 p) { System.out.println("F3"); }
      static void m2(F4 f) { System.out.println("F4"); }

      static String foo(Object in) { return "abc"; }

      static void test(boolean cond) {
        m1(ThisTestClass::foo); // expected: ok; actual: error
        m2(ThisTestClass::foo); // expected: error; actual: ok
      }

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

              Created:
              Updated:
              Resolved: