Lambda Expression Example
//Without Lambda Expression
package govind;
public interface SumInterface
{
public void sum(int a,int b);
}
class Demo implements SumInterface
{
@Override
public void sum(int a, int b) {
System.out.println("Sum="+(a+b));
}
}
package govind;
class Test
{
public static void main(String[] args) {
SumInterface si=new Demo();
si.sum(40, 60);
si.sum(400, 500);
}
}
o/p:--------------------------------
Sum=100
Sum=900
=======================================================================================================================================
//with lambda expression
package govind;
public interface AddInterface {
public void add(int a,int b);
}
package govind;
public class TestAddInterface {
public static void main(String[] args) {
AddInterface ai=(a,b)->System.out.println("Sum="+(a+b));
ai.add(40, 60);
ai.add(400, 500);
}
}
==========================================================================================================================================
o/p:-------------------------
Sum=100
Sum=900
No comments:
Post a Comment