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

JLS8 18.5.3: inference variable seems to be instantiated unexpectedly

XMLWordPrintable

    • b132
    • 8
    • b127
    • Verified

      Let's consider following code:

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

          public void run() {
              Iface<? super Integer, Number> i = (Integer a) -> a.toString();
          }
      }

      It fails with following error:

      Error:(7, 44) java: incompatible types: Test12.Iface<java.lang.Integer,java.lang.Integer> cannot be converted to Test12.Iface<? super java.lang.Integer,java.lang.Number>

      While it should compile successfully since only A1 should be instantiated as a result of reduction in jls-18.5.3-220-A:
      Integer = A1

      While A2 should remain unchanged as Number according to jls-18.5.3-220-B.


      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:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: