Saturday, April 21, 2012

java 1.8 lambda example

I saw at Devoxx France, a conference about java 1.8 and the use of lambdas by Guillaume Tardif. (

In this article, I will show you an example.You can dowload the jdk here :

To install jdk1.8 on Ubunutu, you can do :

sudo mv ./jdk1.8.0 /usr/lib/jvm/
sudo update-alternatives --install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.8/bin/java” 1
sudo update-alternatives --install “/usr/bin/javac” “javac” “/usr/lib/jvm/jdk1.8/bin/javac” 1

sudo update-alternatives --config java

Then, you just have to choose the jdk.

Note : I have a bug when I use javac because javac -version show me always 1.6 and not 1.8
So to compile, I've done the following :

java Main

Here is my file

import java.util.ArrayList;
import java.util.List;

public class Main {

public static void main(String[] args) {
List names = new ArrayList();
names.forEach( (String s) -> { System.out.println(s);} );


Then we show on the screen :


An other important point, Java 1.8 should support multiple inheritance !
If you have comment, post it !