Tuesday, 26 November 2013

A simple program using Lambda Expression

In the process of understanding Lambda expression in java 8 , let us try to understand the simple program given below.  The HelloWorld interface is given an implementation in the main method . After implementation, we use that instance and invoke its single methods. There will be always only one method and so the lambda expression need not specify the method name.

package com
public class LambdaHelloWorld {
  interface HelloWorld {
    String hello(String name);
  }
   public static void main(String[] args) {       
     HelloWorld helloWorld = (String name) -> { return "Hello " + name; };
     System.out.println(helloWorld.hello("Joe"));
  }
}

No comments:

Post a Comment