Lecture 21
Lecture 21
Unit 3
Lecture 21
class Test {
public static void main(String args[])
{
// lambda expression to create the object
new Thread(() -> {
System.out.println("New thread created");
}).start();
}
}
Department of Computer Science ,ABES En
gineering College
Lambda Expression in Java
Lambda Expressions in Java are the same as
lambda functions which are the short block of
code that accepts input as parameters and
returns a resultant value.
Lambda Expression Syntax
arg list -> body
• Zero Parameter
• Single Parameter
• Multiple Parameters
if(isEven.test(10)) System.out.println("10 is
even");
if(!isEven.test(9)) System.out.println("9 is not
even");
}
}
Passing Lambda Expression as arguments
@FunctionalInterface
public interface BinaryOperator<T> extends BiFunction<T, U,
R>
{
……...
}
Department of Computer Science ,ABES En
gineering College
Supplier functional interfaces are also used
for defining the 4. Supplier
logic for the generation of
any sequence.