The following code shows how to create a Thread with Lambda.
//from w w w .j a v a2 s. c om public class Main { public static void main(String... args) { //Anonymous ways Runnable r1 = new Runnable() { public void run() { System.out.println("Hello world from " + Thread.currentThread().getName()); } }; // Runnable is already a functional interface Runnable r2 = () -> System.out.println("Hello world from " + Thread.currentThread().getName()); (new Thread(r1)).start(); (new Thread(r2)).start(); } }
The code above generates the following result.