Array

tronicek at fel.cvut.cz tronicek at fel.cvut.cz
Fri May 16 09:38:08 PDT 2008


{ => } is not legal. Sorry. { => void }[] p = null; compiles right.

Are the changes required to make array of generics safe described anywhere?

Z.
-- 
Zdenek Tronicek
Department of Computer Science and Engineering
Prague                   tel: +420 2 2435 7410
http://cs.felk.cvut.cz/~tronicek


Quoting Rémi Forax <forax at univ-mlv.fr>:

> tronicek at fel.cvut.cz a écrit :
>> Hi,
>>
>> the compiler generates a warning when you call this method:
>>
>>    static { => String } concat({ => String }... arg) {
>>        @Shared
>>        String s = "";
>>        for ({ => String } p : arg) {
>>            s += p.invoke();
>>        }
>>        return { => s };
>>    }
>>
>> It is because the compiler replaces the variable-length arguments   
>> with arrays.
>> E.g.
>>
>>    { => String } p3 = concat({ => "I" }, { => "like" }, { => "closures" });
>>
>> will be transformed to:
>>
>>    { => String } p3 = concat(new javax.lang.function.O[] {{ => "I"   
>> }, { => "like" }, { => "closures" }});
>>
>> And because javax.lang.function.O is a generic type, the compiler complains.
> yes, currently, function type are transformed to generics so you have
> the same limitation.
> By the way, Array of generics are not unsafe, the JLS require to emit
> warning (or error)
> but we found (with Alex Buckley) a way to make them safe.
> This require to change the JLS and this is not backward compatible,
> some warnings are removed
> by some are added but i think it worth the change.
>>
>>
>> Another thing:
>>
>> { => }[] p = null;
> { => } is legal ?
> is it equivalent to { => void } ??
>>
>> does not compile.
>>
>>
>> Zdenek
> Rémi
>> --Zdenek Tronicek
>> Department of Computer Science and Engineering
>> Prague                   tel: +420 2 2435 7410
>> http://cs.felk.cvut.cz/~tronicek
>>
>>
>>
>>
>>







More information about the closures-dev mailing list