Compilation failure on JDK 8 involving inferred generic type

Gunnar Morling gunnar at hibernate.org
Fri Jan 10 04:42:10 PST 2014


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/20140110/d8031cd4/attachment.html 


More information about the compiler-dev mailing list