This post discusses a draft proposal for adding support for closures to the Java programming language for the Dolphin (JDK 7) release. It was carefully designed to interoperate with the current idiom of one-method interfaces. The latest version of the proposal and a prototype can be found at http://www.javac.info/.
My 2006 JavaPolis talk Closures for Java has now been published - slides synchronized with a soundtrack - and can be viewed online at the new Javapolis website, Parleys.com. If you're still wondering why all the fuss about closures, I recommend you listen to the talk.
We've also just published an update to the specification, version 0.4 . The specification seems to be setling down quite a bit, as the changes are minor:
- The throws clause of a function type is now placed between the curly braces.
- The description of function types has been rewritten to emphasize more clearly that function types are interface types rather than a separate extension to the type system.
- The closure conversion can now convert a closure that has no result expression to an interface type whose function returns java.lang.Void. This change helps support completion transparency. A completion transparent method is one written such that the compiler can infer that an invocation completes normally iff the closure passed to it completes normally.
- Some examples have been modified to be completion transparent.
- null is now a subtype of Unreachable, and a number of small related changes. Thanks to Rémi Forax for pointing out the issues.
I hope the talk, which is less technical than the specification, makes it easier for you to evaluate the proposal and compare it to the alternatives.