Compilation failure on JDK 8 involving inferred generic type
Dan Smith
daniel.smith at oracle.com
Tue Jan 21 09:35:00 PST 2014
This looks like a manifestation of JDK-8026527.
We start with a Class<? extends Input>. We perform capture -- Class<CAP>. Now inference concludes that I=CAP, and checks whether CAP is a subtype of Input<O>. It is not -- the raw upper bound 'Input' is not a subtype of any parameterized type.
JDK 8 has not addressed JDK-8026527, but when programs depend on this bug, they've entered an ad hoc space where the compiler does whatever it thinks is reasonable. It does not surprise me, with the changes that were made in inference for 8, that something subtle has changed leading to different ad hoc behavior. (I will say it is weird, though, that compilation depends on whether the target type of the assignment is raw or not.)
—Dan
On Jan 10, 2014, at 6:08 AM, Vicente-Arturo Romero-Zaldivar <vicente.romero at oracle.com> wrote:
> Hi Gunnar,
>
> Yes this is the right list, sorry for the late response. I will look at it.
>
> Thanks,
> Vicente
>
> On 10/01/14 12:42, Gunnar Morling wrote:
>> Hi,
>>
>> Does anyone have an idea whether this is a regression or an intentional change? My apologies, if this is not the right place to ask this question (I'd be happy then about a pointer where to post it instead).
>>
>> Many thanks,
>>
>> --Gunnar
>>
>>
>>
>> 2014/1/3 Gunnar Morling <gunnar at hibernate.org>
>> 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/20140121/9e117ac4/attachment.html
More information about the compiler-dev
mailing list