L23. Lambda Built-In Functional Interfaces
L23. Lambda Built-In Functional Interfaces
By
Arvind Kumar
Asst. Professor, LPU
Functional Interface
A functional interface is an interface that specifies only
one abstract method.
Using Lambda:
(int a, int b) -> (a+b);
OR
(a, b) -> a+b;
Important
When a lambda expression has only one parameter, it is
not necessary to surround the parameter name with
parentheses when it is specified on the left side of the
lambda operator.
Example:
boolean isEven(int n){
return (n%2==0);
}
Using Lambda Expression: n -> (n % 2)==0;
Structure of Lambda Expressions
Argument List:
A lambda expression can contain zero or more arguments.
// No argument
( ) -> { System.out.println("No argument"); }
// Single argument
(int arg) -> { System.out.println(“One argument : " + arg); }
When the code on the right side of the lambda operator consists
of a block of code that can contain more than one statement, It is
called as block body or Block Lambda.
Characteristics of Lambda Expressions
Ans- AB