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

javac, code valid in 7 is not compiling for 8

XMLWordPrintable

    • b23
    • Verified

        This code:

        interface Iface<T1> {}

        class Impl implements Iface<Impl> {}

        class Acceptor<T2 extends Iface<T2>> {
            public Acceptor(T2 obj) {}
        }

        public class Test {
            public static void main(String[] args) {
                Acceptor<?> acceptor = new Acceptor<>(new Impl());
            }
        }

        which is accepted by javac 7 is rejected by javac 8 with this error message:

        Test.java:11: error: incompatible types: cannot infer type arguments for Acceptor<>
                Acceptor<?> acceptor = new Acceptor<>(new Impl());
                                                   ^
            reason: inference variable T2 has incompatible bounds
              equality constraints: Impl
              upper bounds: Iface<CAP#1>,Iface<T2>
          where T2 is a type-variable:
            T2 extends Iface<T2> declared in class Acceptor
          where CAP#1 is a fresh type-variable:
            CAP#1 extends Iface<CAP#1> from capture of ?
        1 error

              mcimadamore Maurizio Cimadamore
              vromero Vicente Arturo Romero Zaldivar
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: