Alex headshot

AlBlue’s Blog

Macs, Modularity and More

Java will have Lambda Expressions

Java 2009

So, it looks like Java will have lambda expressions after all, even if people insist on calling them closures. Assuming it gets in (and there is a JDK 7 eventually) then it will make writing functional code much easier.

The important thing to note, though, is that the correct term is lambda expressions or lambda statements. That's the right term for a parameterised block of code, and the new proposal finally corrects that misnomer. Note that it doesn't prevent them also being closures (i.e. something which captures state outside itself) but that semantically, closures and lambdas are orthogonal concepts. (In other words, there are lambdas that aren't closures – like #bool() {true} – and there are closures which aren't lambdas – such as the inner class Bar in public class Foo { int a; class Bar { int b = a; } }.)

It remains to be seen what the final syntax of the closure ends up being; arguably, part of the verbosity appears to be through Java's lack of type inference (which languages like Scala show are possible). Still, if and when they finally make it in, it will be a boon for the otherwise slowly fossilising Java language.

Update: Mark Reinhold has just proposed Project Lambda to bring them to the OpenJDK.