Thursday, February 7, 2013

Time to meet Java 8 with Lambda Expressions!

The Java 8 development is on its way an the (nearly) feature complete JDK 8 M6 (build b75) release was published on 2013/01/31. This version contains the Lambda Expressions - so time to meet!

The JDK 8 M6 is available on the JDK 8 project site. The installation process is simple and (as far as I noticed) does not contain any Ask toolbar installation option ;-) After the installation my system featured the following java version:

C:\>java -version
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b75)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b17, mixed mode)


The Project Lambda provides a Netbeans 8 Nightly Build with experimental Lambda support but as my first example is trivial I just ignored the IDE compiler warnings and compiled and ran the class from the command line.

And that's it. Comparator implementation with Lambda Expressions:

As hoped (and expected) the output is:

[1, 2, 3]
[3, 2, 1]


 No big deal but I am glad it worked! Now I am ready to move on...

Some links:

Update: It turned out that the JDK M6 build is not feature complete yet. The current status is explained by Mark Reinhold here