Thursday, December 02, 2010

Java closure shows his face - Lambda expression

JSR335, Lambda expression started review ballot stage on November 16th 2010. Java closure finally show the new breath taking expression. Citing from the detail of JSR request:

2.7 Please give a short description of the underlying technology or technologies:

We propose extending the Java Language to support compact lambda expressions (otherwise known as closures or anonymous methods.) Additionally, we will extend the language to support a conversion known as "SAM conversion" to allow lambda expressions to be used where a single-abstract-method interface or class is expected, enabling forward compatibility of existing libraries.

We propose extending the semantics of interfaces in the Java Language to support virtual extension methods, whereby an interface can nominate a static default method to stand in for the implementation of an interface method in the event that an implementation class does not provide an implementation of the extension method. This enables interfaces to be augmented with new methods "after the fact" without breaking existing implementation classes.

Time permitting, we will use these features to augment the core Java SE libraries to support a more lambda-friendly style of programming, such as:
Collection collection = ... ;
collection.sortBy(#{ Foo f -> f.getLastName() });

collection.remove(#{ Foo f -> f.isBlue() });
This will likely be accompanied by a set of standardized "SAM" types such as Predicate, Filter, Mapper, Reducer, etc.

No comments: