Monday 29 May 2017

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


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

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/LambdaDemo_parenthesis_app

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/4c13bd19ff03c6acdc5e87d7803290d625ce640a/BasicJava/LambdaDemo_parenthesis_app/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment