Thursday, 8 June 2017

Lambda expression in java [How to implement the Functional interface - GreetingService] ~ foundjava


Click here to watch in Youtube :
https://www.youtube.com/watch?v=91sd5c23Eoo&list=UUhwKlOVR041tngjerWxVccw



LambdaDemo.java

@FunctionalInterface
interface GreetingService
{
    void sayMessage(String message);
}

public class LambdaDemo
{

    public static void main(String[] args)
    {

        // with parenthesis
        GreetingService greetService1 = message ->
                          System.out.println("Hello " + message);

        // without parenthesis
        GreetingService greetService2 = (message) -> 
                          System.out.println("Hello " + message);

        greetService1.sayMessage("Peter");
        greetService2.sayMessage("John");
    }

}
Output
Hello Peter
Hello John
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/LambdaDemo_parenthesis_app.zip?attredirects=0&d=1

No comments:

Post a Comment