Over a million developers have joined DZone.

Update on Closures Coming to Java 7

· Java Zone

Learn more about how the Java language, tools and frameworks have been the foundation of countless enterprise systems, brought to you in partnership with Salesforce.

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.

Discover how the Force.com Web Services Connector (WSC) is a code-generation tool and runtime library for use with Force.com Web services, brought to you in partnership with Salesforce.

Topics:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}