Nested generics don't compile in 1.7.0_15, but do in 1.6.0_27.
Zhong Yu
zhong.j.yu at gmail.com
Tue Mar 12 09:48:19 PDT 2013
On Tue, Mar 12, 2013 at 10:34 AM, Maurizio Cimadamore
<maurizio.cimadamore at oracle.com> wrote:
> On 12/03/13 15:07, Zhong Yu wrote:
>>
>> Class<? extends SubFoo> c1 = SubFoo.class;
>
> This shoud compile, in fact the type of SubFoo.class is Class<? extends
> SubFoo>.
>
>> Class<? extends FooString> c2 = c1;
>
> This should also compile:
>
> Class<? extends SubFoo> <: Class<? extends FooString>
> SubFoo <: FooString
>
> which is true as FooString is a supertype of the raw SubFoo.
>
>> Class<? extends Foo<String>> c3 = c2;
>
> This should also compile:
>
> Class<? extends FooString> <: Class<? extends Foo<String>>
> FooString <: Foo<String>
>
> which is true (by class definition)
>
>> but then this fails
>>
>> c3 = c1;
>
> This is is correctly rejected:
>
> Class<? extends SubFoo> <: Class<? extends Foo<String>>
> SubFoo <: Foo<String>
>
> Note that since we are not using unchekced subtyping recursively, the above
> is not true. SubFoo has a raw supetype of Foo, not Foo<String>
Transitivity seems broken; we have
SubFoo <: |FooString|=FooString
FooString <: Foo<String>
but not
SubFoo <: Foo<String>
Apparently the problem lies at |FooString|=FooString. The two types
probably should have been distinctive, since FooString is kind of
generic, even though it carries no type parameters on itself.
Zhong Yu
More information about the compiler-dev
mailing list