To understand the concept of lambda expression we need to have a clear understanding of what is a Functional Interface
An interface which declares only one abstract method is called as Functional Interface and lambda expressions let us provide the implementation of the abstract method of a Functional Interface
interface Finterface{
public abstract void functionalInterfaceMethod();
}
Now we can have the implementation of this functional interface either by using anonymous inner classes or by using the Lambda expressions
Using Anonymous inner class
Finterface finterface=new Finterface(){
public void functionalInterfaceMethod(){
System.out.println("Example lambda!");
}
};
or using Lambda expression
Finterface finterface=()->System.out.println("Example Lambda!");
()->System.out.println(“Example Lambda!”);–> provide the implementation of Finterface.
The signature of the abstract method of a functional interface describes the signature of lambda expression called as Functional Descriptor as in the above example the functionalInterfaceMethod declares that is doesn’t accepts any parameter and returns void
the same is the description of its Lambda
()# Zero parameters
-># separates the parameter with expression
System.out.println()# Expression returning void