arrays and raw types in 18.2.3
Dan Smith
daniel.smith at oracle.com
Tue Oct 15 15:24:43 PDT 2013
On Oct 15, 2013, at 4:04 PM, Dan Smith <daniel.smith at oracle.com> wrote:
> On Oct 10, 2013, at 6:01 AM, Stephan Herrmann <stephan.herrmann at berlin.de> wrote:
>
>>>> I'm currently looking at this test:
>>>>
>>>> public class X {
>>>> public static void main(String[] args) {
>>>> EntityKey entityKey = null;
>>>> new EntityCondenser().condense(entityKey);
>>>> }
>>>> public static class EntityCondenser {
>>>> <I, E extends EntityType<I, E, K>, K extends EntityKey<I>> void condense(K entityKey) {
>>>> }
>>>> }
>>>> public class EntityKey<I> {}
>>>> public interface EntityType<
>>>> I,
>>>> E extends EntityType<I, E, K>,
>>>> K extends EntityKey<I>> {
>>>> }
>>>> }
>>>
>>> Ah, okay, in this case, there is no compatibility constraint for the two types ("Raw -> Parameterized"), just a subtyping constraint ("Raw <: Parameterized"), which is derived from the bound of K.
>>>
>>> The old spec was somewhat vague here, but I believe the correct behavior for both 7 and 8 is to fail.
>>
>> If that is so, then all(?) existing compilers have a bug: they do accept this program.
>> I just checked, even javac8 b109 accepts the above test.
>> Will this be changed in the near future?
>
> It would not surprise me if there are some subtle changes between JLS 7 and JLS 8 lurking here, but I'm confident that JLS 7 calls this particular example an error.
>
> I've confirmed that this is longstanding behavior in javac, and will report a bug.
>
> ---
>
> Here's a simplified variation:
>
> class EntityKey<T> {}
>
> <I, K extends EntityKey<I>> void condense(K entityKey) {}
>
> EntityKey entityKey = null;
> condense(entityKey);
Turns out this problem is actually independent of inference: the following will also compile with both javac and ecj:
EntityKey entityKey = null;
this.<Object,EntityKey>condense(entityKey);
—Dan
More information about the lambda-spec-observers
mailing list