Array
Rémi Forax
forax at univ-mlv.fr
Fri May 16 09:21:02 PDT 2008
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