November 19, 2009

Closures for Java 7

Yes it's true! Java 7 will indeed have closures. I was enthusiastically following the Java closures war in 2007, and subsequently had lost hope that Java will ever have closures. But now it seems like the heads at SUN have changed their minds after all. This was announced by Mark Reinhold at devoxx.

Let's hope they do it right. Which of the various closure proposals will be used? Apparently it will be a mix of them all. Syntax-wise it resembles the simplistic FCM proposal, semantic-wise it partly uses the BGGA approach: seems like assignments to captured non-final variables could be in, but non-local transfers will be out (using break or continue within closure code will yield a compile-time error). Sadly this also strikes out BGGA's innovative control-statement-invocation syntax. Anyway, they have changed their decision once so there is still hope for more BGGA support.

Some quick links pointing to various sources of this news:

Updates:

Catched a comment from Neal Gafter on Ted Newards blog:
I had been discussing this spec [BGGA 0.6a] with Gosling, but I have had no contact with Reinhold.
And another one on Cay Horstmans blog:
the 0.6a specification is NOT BGGA, nor is it intended to document Mark Reinhold's plans for JDK7. [...] it resulted from a discussion with the other authors of the BGGA spec culminating in this document a couple of weeks ago [...] I was attending PDC09 when I read a tweet about closures and put up the link. I think the timing and similarity to Mark Reinhold's announcement are either coincidental or Gosling has passed it on to him. [...] Note that this spec allows access to non-final local variables from the enclosing scope, which rumors suggest Reinhold has ruled out.
It's a shame Neal does not blog about closures himself anymore.

No comments:

Post a Comment