Over a million developers have joined DZone.

Update on Closures Coming to Java 7

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

It was announced yesterday that closures would be added to JDK 7.  Mark Reinhold made the announcement at the Devoxx conference.  Before today, Sun could not reach a consensus on the inclusion of closures in JDK 7.  Three proposals for closures were submitted to Sun over the last few years.  With the JDK 7 schedule extended to September 2010, Reinhold seems to think that now is the time to bring closures to Java.

A few more details about the closures announcement for Java 7 surfaced today.  According to Stephen Colebourne's blog, Mark Reinhold's Devoxx announcement indicated that "JDK 7 closures will not have control-invocation statements as a goal, nor will it have non-local returns.  He [Reinhold] also indicated that access to non-final variables was unlikely.  Beyond this, there wasn't much detail on semantics, nor do I believe that there has been much consideration of semantics yet."

Here's a strawman syntax for closures that Mark Reinhold wrote on his plane ride to the conference:

  // function expressions
#(int i, String s) {
System.println.out(s);
return i + s.length();
}

// function expressions
#(int i, String s) (i + s.length())

// function types
#int(int, String)



The syntax resembles the FCM closure proposal, but Reinhold made it clear that he was using FCM as an example and not endorsing it.  Joseph Darcy from Sun said the closures would be "Smaller than BGGA."  A few weeks before the conference, Neal Gafter, a co-author of the BGGA closure proposal, wrote a simple specification for closures in Java.

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}