We have written a simple HelloWorldLambdas class to illustrate the usage of
lambda Expression.
We have declared an interface Greeting with a single abstract method sayHello.
A testGreetingmethod with parameters as String and Greeting .
From the main class we instantiate the HelloWorldLambdas class
to invoke the test Greeting with lambda expression.
package com.consciousprogramming.LambdaExpressions.examples;
public class HelloWorldLambdas {
interface Greeting{
String sayHello(String greeting);
}
public void testGreeting(String input, Greeting greeting){
String result= greeting.sayHello(input);
System.out.println(result);
}
public static void main(String [] args){
new HelloWorldLambdas().testGreeting("World",(s)->"Hello "+s);
new HelloWorldLambdas().testGreeting("",(s)->s.isEmpty()?"Input not provided":"Hello"+s);
}
}
Comments
Post a Comment