A lambda can be written as a single expression whose value is returned implicitly, or as a braced block with an explicit return statement and explicit parameter types; both forms produce the same functional interface implementation.
BinaryOperator<Integer> addExpr = (a, b) -> a + b;
BinaryOperator<Integer> addBlock = (Integer a, Integer b) -> {
int sum = a + b;
return sum;
};
System.out.println("Expression body: " + addExpr.apply(2, 3));
System.out.println("Block body: " + addBlock.apply(2, 3));
Expression body: 5
Block body: 5
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27