A syntax option (function types versus arrays)
Gernot Neppert
mcnepp02 at googlemail.com
Wed Mar 10 23:50:29 PST 2010
>
> A possible alternate syntax is:
>
> #< R( A ) throws E > example = new #< R( A a ) throws E >( ... );
>
I like the following two things about this syntax:
firstly, the use of "new" to create a lambda. This makes it consistent
with other object instantiations (in this case, an object of function
type being created).
secondly, the idea to re-use the syntax for parameterized types.
However, I do not like these two things:
firstly, as a matter of personal taste, the token sequence '#<' looks
rather ugly, especially if nested.
secondly, borrowing the syntax from generic type declarations seems
half-hearted: there are still parentheses within the '<>' tokens.
Why not go all the way to:
lambda<void,byte[],int,int, throws IOException> writer = new
lambda<void,byte[] buf, int off, int len, throws IOException> {
System.out.write(buf, off, len);
}
The keyword 'lambda' introduces the generic function type.
At least one type variable must follow, indicating the return type.
Further type variables may follow, indicating the argument types.
Further type variables may follow the keyword 'throws', indicating the
types of the checked Exceptions being thrown.
More information about the lambda-dev
mailing list