FINAL PROPOSAL: Closures for Java

Neal Gafter neal at
Thu Feb 28 23:24:09 PST 2008

FINAL PROPOSAL: Implement Closures for Java

          Neal Michael Gafter
	  neal at

Implement Lambda Expressions, Function Types, and Control Abstraction

I propose to produce a feature-complete prototype of the Java bytecode
compler (javac) features for the Closures specification appearing at suitable for integration into
the openjdk javac compiler as part of the reference implementation of
a future platform specification.  The specification includes the
following major features

  o  closure literals (sometimes called lambda expressions)
  o  function types
  o  control invocation statements

This includes support for the following component features

  o  restricted and unrestricted forms
  o  the closure conversion
  o  exception type parameters
  o  union types
  o  definite assignment
  o  the type Unreachable (to be renamed Nothing)
  o  loop abstractions
  o  access to non-final variables within a closure

The prototype shall be complete in providing support for all
features of the specification, including those described above, as
well as supporting "nonlocal" return, break, and continue in
unrestricted contexts.

The Clear Need

A discussion of the needs satisfied by this proposal appears in a
draft JSR proposal at
In summary, the draft specification supports the development and use
of APIs that significantly improve the use of concurrency for
multicore systems, and enables the development of APIs that
significantly reduce boilerplate for some common programming patterns.

Development Guidelines

Devlopment of the prototype shall take place as an openjdk project to
be created within the openjdk compiler group, in accordance with the
prevailing community governance procedures for such development.  The
prototype shall be contributed under the Sun Contributor Agreement.

Dependence on Sun and other resources

While the development of the specification is outside the scope of
this project, it is likely that the specification will evolve in
response to community feedback.  For example (as discussed in the
draft JSR specification) I expect to add support for constructing a
closure by reference to an existing Java method ("method reference").
Any such changes in the specification shall be followed by inclusion
of those changes in the scope of the project.

Development of the prototype shall take place independently of Sun
Microsystems.  I expect involvement of Sun Microsystems employees -
particularly Alexander Buckley, the editor of the Java Language
Specification, and Maurizio Cimadamore, a specialist in type systems,
in refining the specification and providing feedback about
specification changes that will be necessary to integrate the work
into the Java Language Specification and to integrate it with other
language changes that might be under consideration.  Such
specification refinements shall be reflected in the prototype.  In
addition, I expect continued collaboration with other authors on the
draft specification, including specifically Gilad Bracha, James
Gosling, and Peter von der Ahe.

Additional work may be desireable in the virtual machine or core
libraries in support of this work.  For example, it would be useful
for the virtual machine to provide support for proper tail recursion
and to generate function type interfaces on demand.  It would be
helpful to extend the reflection libraries to support the new
features.  Such additional specification and implementation work is
outside the scope of this project.

Project Plan and Milestones

Development shall proceed as follows:

     An initial prototype shall be published as an openjdk patch,
     providing support for most of the features of the specification
     with unit tests and regression tests.

     An extension of the com.sun.source, javax.lang.model, and javadoc
     APIs shall be included in a revision of the prototype.

     An update to the prototype shall be published that provides
     support for nonlocal return, break, and continue, and any other
     remaining features from the initial specification.

     Any specification changes preceding 2008-06-01 shall be reflected
     in a revision of the prototype.

     Final, feature-complete submission of the Closures prototype
     shall be delivered at this time.

In addition to these milestones, I expect to provide regular prototype
updates in response to bug reports from users.

While not formally part of the project, I expect to recommend JVM,
library, and other platform changes that are likely to improve
performance, usability, or integration with the platform or other
language changes likely to be included at the same time as closures.


This proposal, in its entirety, is hereby contributed under the terms
of the Sun Contributor Agreement.

More information about the challenge-discuss mailing list