This program compiles fine in Java 7 (or in Java 8 with -source 7), but fails to compile with Java 8:
interface Iface {}
class Impl implements Iface {}
class Acceptor> {
public Acceptor(T obj) {}
}
public class Main {
public static void main(String[] args) {
Acceptor> acceptor = new Acceptor<>(new Impl());
}
}
Result:
Main.java:10: error: incompatible types: cannot infer type arguments for Acceptor<>
Acceptor> acceptor = new Acceptor<>(new Impl());
^
reason: inference variable T has incompatible bounds
equality constraints: Impl
upper bounds: Iface,Iface
where T is a type-variable:
T extends Iface declared in class Acceptor
where CAP#1 is a fresh type-variable:
CAP#1 extends Iface from capture of ?
1 error
In other words, this is a backwards source incompatibility between Java 7 and 8. I've gone through Incompatibilities between Java SE 8 and Java SE 7 list but did not found anything that would fit my problem.
So, is this a bug?
Environment:
$ /usr/lib/jvm/java-8-oracle/bin/java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
解决方案
Thanks for the report. This looks like a bug. I will take care of it and probably add a better answer once we have more information about why this is happening. I have filed this bug entry JDK-8043926, to track it.