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

JLS8 9.9: non-wildcard parameterization succeeds unexpectedly

XMLWordPrintable

    • Fix Understood
    • b132
    • 8

      Let's consider following code:

      public class Test13 {
          interface Iface<A1, A2 extends A1> {
              String m(A1 t);
          }

          static void m(Iface<? super Number, ? super Integer> i) {
          }

          public static void run() {
              m((Number a) -> a.toString());
          }
      }

      It compiles successfully.

      While according to 18.5.3:
      1. Just one constraint Number=A1 is created causing only A1 to be instantiated in jls-18.5.3-210.

      2. A2 is left unchanged as "? super Integer" as it's specified by jls-18.5.3-220-B. So jls-18.5.3-220 finally should yield Iface<Number, ? super Integer>.

      3. According to jls-18.5.3-230 since second type argument contains wildcard, non-wildcard parameterization should be the resulted parameterization.

      4. But the non-wildcard parameterization should fail according to jls-9.9-200-C.1-B because second type argument is a wildcard and corresponding type parameter is bound by type parameter (A2 extends A1).

      5. So finally the compilation should fail while actually it succeeds.

      It looks like resolution takes place along with reduction in jls-18.5.3-210 in javac.

            vromero Vicente Arturo Romero Zaldivar
            grakov Georgiy Rakov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: