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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.List; | |
public class LambdaCompare { | |
public static void main(String[] args) { | |
// sort ascending | |
List<Integer> listAsc = new ArrayList<>(); | |
listAsc.add(3); | |
listAsc.add(1); | |
listAsc.add(2); | |
Collections.sort(listAsc, (Integer o1, Integer o2) -> { return o1.compareTo(o2); }); | |
System.out.println(Arrays.toString(listAsc.toArray())); | |
// sort descending | |
List<Integer> listDesc = new ArrayList<>(); | |
listDesc.add(3); | |
listDesc.add(1); | |
listDesc.add(2); | |
Collections.sort(listDesc, (Integer o1, Integer o2) -> { return o2.compareTo(o1); }); | |
System.out.println(Arrays.toString(listDesc.toArray())); | |
} | |
} |
[1, 2, 3]
[3, 2, 1]
No big deal but I am glad it worked! Now I am ready to move on...
Some links:
- OpenJDK
- JDK 8 project
- Project Lambda
- State of the Lambda by Brian Goetz
- Java 8 blog posts by +Christian Ullenboom (german)
Update: It turned out that the JDK M6 build is not feature complete yet. The current status is explained by Mark Reinhold here