JDK-8043926 : javac, code valid in 7 is not compiling for 8
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,9
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2014-05-23
  • Updated: 2016-01-22
  • Resolved: 2014-07-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
8u40Fixed 9 b23Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
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
ILW evaluation = MML -> P4, reassigning priority.

Dan Smith's analysis on this: From overload resolution, we infer { t2 <: Object, Impl <: t2, t2 <: Iface<t2> } Incorporation then yields: t2 = Impl The target type constraint is: Acceptor<t2> -> Acceptor<?> Which doesn't add any constraints.

originally reported in SO: stackoverflow.com/questions/23063474/why-does-this-java-8-program-not-compile