Syntax...
Neal Gafter
neal at gafter.com
Sat Nov 21 08:10:56 PST 2009
On Sat, Nov 21, 2009 at 5:21 AM, Jakob Praher <jp at hapra.at> wrote:
> File f = new FIle(".");
> File[] textfiles = f.listFiles( new (File pathname) {
> pathname.endswith("txt") } );
>
The problem with "new" is that a lambda expression should not require the
creation of a new object at each evaluation. If the lambda captures no
state from the enclosing context, the compiler should be free to allocate it
statically.
> "new" is surely debatable and one could think about omitting it.... Then
> one could also think about more scala like:
>
> f.listFiles (File pathanme) {
> return pathname.endswith("txt") ;
> }
>
I don't believe that can be retrofitted onto the Java language without
syntactic ambiguity.
> If the only argument to a method is a closure, one could leave out the
> parenthesis and it looks much more readable IMHO.
> Surely this would be a bigger burdon to the compiler, but even with the
> parenthesis around it would be readable, no?
>
> f.listFiles( (File pathanme) {
> return pathname.endswith("txt") ;
> });
>
Yes, this was what we had back in BGGA version 1. We'd really like to
eliminate the "return" boilerplate.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20091121/3ec95a71/attachment.html
More information about the closures-dev
mailing list