Closures in Java 7.0

by Krishna Srinivasan

I am just trying in google to know what is in next version of Java. So many blogs writing about the new feature closures in Java 7.0, a functional programming cocept.

An excerpt from sun blogs:

Modern programming languages provide a mixture of primitives for composing programs. C#, Javascript, Ruby, Scala, and Smalltalk (to name just a few) have direct language support for function types and inline function-valued expression, called closures. A proposal for closures is working its way through the C++ standards committees as well. Function types provide a natural way to express some kinds of abstraction that are currently quite awkward to express in Java. For programming in the small, closures allow one to abstract an algorithm over a piece of code; that is, they allow one to more easily extract the common parts of two almost-identical pieces of code. For programming in the large, closures support APIs that express an algorithm abstracted over some computational aspect of the algorithm. We propose to add function types and closures to Java. We anticipate that the additional expressiveness of the language will simplify the use of existing APIs and enable new kinds of APIs that are currently too awkward to express using the best current idiom: interfaces and anonymous classes.


Java 7.0 (Dolphin) Resources and New features (Closures)


9 Comments

Bob R
2006-12-16 20:13:57
Let's keep Java fun and simple and stop cluttering it with garbage.
Kazushi Sakuraba
2006-12-17 04:37:34
Closures possess the power to either bring another elegant feature to the Java language OR to make the language hard to understand and unreadable.


Same goes with operator overloading.


Only time will tell what is gonna happen.

J. Keplinger
2006-12-17 08:27:20
I rather like the idea of closures for use as callbacks. Sometimes we need to send messages that don't make sense to model as events.
Chris Treber
2006-12-17 15:42:13
Way too late. Why isn't this is Java 6?

2006-12-18 02:37:16
Closures are not necessarily "a functional programming cocept."(sic) Rather they are fundamental to implementing data hiding in OO languages. This is apparent from languages that expose the implementation of their OO system, including Javascript and Perl. I would not be surprised to find out that under the hood Java uses closures to implement data hiding too.
me
2006-12-18 10:27:46
All dynamic languages had these for ages...
What I see is that Java started to adopt ideas which
was "rejected" at the begining, to preserve the language simple.
But as we saw Iterators and now Closures java will loose its
"simplicity" (i.e. overdesign ;) ).
In my opinion, I welcome the changes but they are too late ;(.
From the java-purist standpoint it is not good ;).
James Carr
2006-12-19 08:19:26
I have been either "rolling my own" or using the predicates and closures in apache commons collections package with a lot of success.... almost all of my custom domain collections contain a method like void forAll(Closure foo) that I do stuff like:


businesses.forAll(println());


or


businesses.forAll(upTo(10, process());


It's great fun. ;)

Evan W
2006-12-21 12:32:36
Is This the same concept as C# delegates or C++ functors?
dsddad
2007-03-30 01:09:34
sdadasdasd