To write a lambda expression, the interface should have only one abstract method. If an interface has more than one abstract method, we cannot write lambda expression.
When we work as a team, someone creates an interface to write a lambda expression. Later, another team member can add another abstract method to that interface to fulfill his requirement. But in this scenario, that change will effect to the lambda expression and it will not work.
To avoid above scenarios, we need to tell specifically, this interface should have only one abstract method.
We have a lovely annotation to cater this requirement as@FunctionalInterface. It restricts the adding more than one abstract method to the interface.
Find the below sample:
Enjoy...!!
When we work as a team, someone creates an interface to write a lambda expression. Later, another team member can add another abstract method to that interface to fulfill his requirement. But in this scenario, that change will effect to the lambda expression and it will not work.
To avoid above scenarios, we need to tell specifically, this interface should have only one abstract method.
We have a lovely annotation to cater this requirement as
@FunctionalInterface
public interface Greeting {
String perform( String s) ;
}
Enjoy...!!
No comments:
Post a Comment