Compilation failure on JDK 8 involving inferred generic type
Gunnar Morling
gunnar at hibernate.org
Fri Jan 3 02:12:51 PST 2014
Hi,
I'm investigating a compilation error which I'm seeing when compiling the
Bean Validation TCK using JDK 8 (build 121). The following example shows
the issue:
public class GenericsTest {
public class Input<O extends Output<O>> {}
public class Output<O extends Output<O>> {}
public class OutputContainer<O extends Output<O>> {}
public <O extends Output<O>, I extends Input<O>> OutputContainer<O>
process(
Class<I> inputType) {
return null;
}
public void testProcess() {
Class<? extends Input> inputType = null;
//next line compiles with source level 1.7 but fails with
source level 1.8
OutputContainer<?> outputContainer = process( inputType );
}
}
This code used to compile with JDK 7 and it also does with JDK 8, when
using 1.7 as source level. But it fails with source level 1.8, saying:
"incompatible types: inferred type does not conform to upper bound(s)"
I can make the code compile when declaring the outputContainer variable of
the raw type OutputContainer instead of declaring it with the wildcard
parameter.
Is this an intentional change in JDK 8 or is it some kind of regression? If
it is intentional, maybe the error message should be a bit more
descriptive, mentioning the concerned inferred type and the bounds?
Many thanks,
--Gunnar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20140103/a8d76a3e/attachment.html
More information about the compiler-dev
mailing list