Update on Closures Coming to Java 7
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.






Comments
Collin Fagan replied on Wed, 2009/11/18 - 5:47pm
Mitch Pronschinske replied on Wed, 2009/11/18 - 6:11pm
in response to:
Collin Fagan
Silvio Bierman replied on Wed, 2009/11/18 - 8:08pm
Collin Fagan replied on Wed, 2009/11/18 - 9:11pm
in response to:
Ryan De Laplante replied on Thu, 2009/11/19 - 8:53am
When will people realize that the majority of Java programmers aren't nearly as dissatisfied with the language as functional programmers seem to think? Give me NIO2, properties, a better date & time API, multi catch, the "elvis operator", USB & Serial ports on all OS's, and Java EE 6 instead. Hopefully once Oracle takes over Sun they will have the money and manpower to increase the pace of enhancement to the Java language. Since JDK7's release date has been pushed way out, maybe they can finally include these kinds of useful features.
Sven Reimers replied on Thu, 2009/11/19 - 1:25am
Alex Miller replied on Thu, 2009/11/19 - 2:12am
Felipe Gaúcho replied on Thu, 2009/11/19 - 3:26am
Eugene Kisly replied on Thu, 2009/11/19 - 4:03am
Armin Ehrenreich replied on Thu, 2009/11/19 - 4:08am
or when separating declaration and definition:Liam Knox replied on Thu, 2009/11/19 - 4:48am
in response to:
Silvio Bierman
Look at the history of other language usage, for example C++ or even Corba, in the real world and you will see its not just question of picking up the next 'great' language and starting again. It is often slightly more technically and politically complex than you infer
Closures will help Java developers although there is controvesy. I personally believe it is excellent news.
Karl Peterbauer replied on Thu, 2009/11/19 - 6:34am
in response to:
Liam Knox
+1. Good news for Javaland, no matter which syntax they finally pick.
With several thousands lines of Java code to maintain the next years, I never understood those cynical "Why don't you switch to Scala/Groovy/SomeOtherJVMBaseLanguage?" arguments.
Silvio Bierman replied on Thu, 2009/11/19 - 11:24am
in response to:
Liam Knox
Armin Ehrenreich replied on Thu, 2009/11/19 - 12:20pm
in response to:
Silvio Bierman
http://www.indeed.com/jobtrends?q=Java%2C+C%23%2C+Scala%2C+Ruby&l=
Ryan De Laplante replied on Thu, 2009/11/19 - 12:51pm
in response to:
Armin Ehrenreich
Change the C# to .NET in your trend, and it shows .NET overtaking Java in 2005
http://www.indeed.com/jobtrends?q=Java%2C+.NET%2C+Scala%2C+Ruby&l=
I was a bit surprised to see this
Karl Peterbauer replied on Thu, 2009/11/19 - 1:28pm
in response to:
Silvio Bierman
GeekyCoder coder replied on Thu, 2009/11/19 - 2:27pm
There are many good valid points either in freezing Java or adding 'compelling' feature to Java language.
I like to give my point of view too.
I support the idea that Java as a language need to evolve by adding 'marketable' and 'useful' feature. Although freezing Java does not make it any less popular in near future since there are already huge investment in Java-written software, Java language need to have good 'attractive' feature to continuously entice new programmers and retain developers to build Java application. If change is inevitable, why does that not apply to programming language as well ? Beside, it is also in the best interest for companies that bet on Java technology for their business like Oracle, IBM, to continously make Java as attractive development language since a greal deal of their software are written in Java-only language, and will need Java programmer to maintain and enhance them. Moreover, if these companies are continue to use Java for their future project and new product, why then not improve Java to leverage on existing skill and experience ? After all, at the end of the day, what matter most is application get developed and programmers are happy to use and to exploit Java's feature.
Moreover Java to some is also both a passion and testbed for language innovation, and by improving the Java language, it also make for more interesting Java-derivative language (eg Groovy), . Perhaps it is the hope that Java still has promising life and innovation ahead in term of language feature that spurt more attractive language, library and framework. For example, library and framework are updated to exploit Generic, var-arg, Annotation, and the same will happen for Closure.
Eventually language will be overtaken by another better and popular language but if the language's life can still be prolonged by adding marketable feature, then why not ? If Java becomes marketable and popular, the programmer too will become marketable and in demand too. I hardly believe that Java will become the future Cobol as long as it continue to evolve with 'marketable' feature.
Let nature takes its course on Java but Java itself should not standstill to await its fate.
My wish-list for Java7 => G-String / Multiline string, closure
GeekyCoder coder replied on Thu, 2009/11/19 - 2:42pm
Why do we not want Java language to evolve when other alternate languages (eg Groovy, Scala, Fantom, JRuby) are continuously evolve with interesting and marketable features ? To say that Java should stay stagnant for reliability purposes , and that other languages can be used for Java's lackof feature (eg closure) are quite ironic because what make those latter languages anymore reliable with continuous change ?
Armin Ehrenreich replied on Thu, 2009/11/19 - 3:13pm
in response to:
Ryan De Laplante
Liam Knox replied on Thu, 2009/11/19 - 8:49pm
in response to:
Silvio Bierman
I would also say thay both Generics and Annotations have done this too for Java.
If you think that Closures add less value, i.e. by way of complexity, then clearly you would advise otherwise. Presumably as you like Scala you like Closures. Again, you have to think real world though. Yes it would be great to pick up Scala and use it everywhere from now, but that is not going to happen and preventing Java improvement based on this premis is plain wrong.
Look how evolution works interms of iteration and mutation, small step, big step you should get the general idea. Software languages have synergy to this.
Chris Knoll replied on Fri, 2009/11/20 - 10:19am
Can we please boot the people that are comming up with these stupidly terse synatx ideas?
In the old days, it was nice...you could read the code naturally and it made sense.
It started with the : operator....would 'foreach' have been such a problem? But it's the 'extends' keyword in other languages.
Now we have this #. Isn't that a way to mark a line a comment?
why's it so hard to type:
function x(int y,string z);
If they want to save characters, how about we rewrite the whole laugnage syntax...let's start with variable declarations...here's how we can map it out
int = .
string = $
bool = ?
float = %
double = %%
new = +
Think of all the typing savings!
. x = 4;
$ y = "Love the savings!"
/sarcasm
Someone tell me...WHY does java additions need to look like objective-C? It didn't start out that way, and making the new things model some other language just makes the whole thing look like a hodgepodge of disjointed ideas. It's like we have the wrong decision makers at the helm...
Neal Gafter replied on Fri, 2009/11/20 - 12:02pm
Silvio Bierman replied on Fri, 2009/11/20 - 12:50pm
in response to:
Liam Knox
Rogerio Liesenfeld replied on Fri, 2009/11/20 - 4:17pm
in response to:
Armin Ehrenreich
Personally, my hopes lie with JavaFX Script. Scala has no chance in the long term, IMO...
cowwoc replied on Fri, 2009/11/20 - 11:22pm
Chris Knol is completely right.
Readability should come first!
Liam Knox replied on Sat, 2009/11/21 - 6:05am
in response to:
Silvio Bierman
Armin Ehrenreich replied on Sat, 2009/11/21 - 5:27am
in response to:
Rogerio Liesenfeld
Armin Ehrenreich replied on Sat, 2009/11/21 - 6:19am
in response to:
Chris Knoll
function x(int y,string z);
or maybe a keyword block instead of # which really looks like a comment.
Joerg Wassmer replied on Sat, 2009/11/21 - 7:56am
Mario Fusco replied on Sat, 2009/11/21 - 10:08am
This proposal provides more or less the same set of features offered by lambdaj (actually lambdaj has also curry that seems missing in this spec). The only advantage i can see here is a nicer syntax.
But I took 3 days to develop closures in lambdaj, while (if everything will go as claimed and I am not sure of that) it will need about 3 years to have the same stuff in jdk7. Indeed I remember I am participating to discussion about closures since late 2007 and now they are telling us that we will have them in late 2010.
The elephant is going to give birth the mice.