I'm assuming the method of the functional interface implemented by this lambda expression has a return value, so when using brackets, it should include a return statement, just like any method with non-void return type.

new JdbcTemplate(new SingleConnectionDataSource(c, true))
    .query("select id, name from PLAYERS", (rs, rowNum) ->
        {
            return new Player(rs.getString("id"), rs.getString("name");
        }) 
    );
Answer from Eran on Stack Overflow
🌐
W3schools
codesjava.com › home
Best Place For Technologies And Academics Tutorial
August 6, 2014 - Free Online Tutorials, W3schools provides tutorials and interview questions of all technology like java, android, physics, chemistry, math, english, javascript, ajax, core java, sql, python, php, c language etc.
🌐
TutorialsPoint
tutorialspoint.com › article › how-can-we-write-a-multiline-lambda-expression-in-java
How can we write a multiline lambda expression in Java?
([comma seperated argument-list]) -> { multiline statements } interface Employee { String displayName(String s); } public class MultilineLambdaTest { public static void main(String[] s) { Employee emp = <strong>(x) -> {</strong> // Lambda Expression with multiple lines x = "Jai " + x; System.out.println(x); return x; }; emp.displayName("Adithya"); } }
🌐
W3Schools Blog
w3schools.blog › home › java 8 lambda expression multiple statements
Java 8 lambda expression multiple statements - w3schools.blog
April 14, 2018 - Lambda expression is used to provide the implementation of functional interface. ... Where: Argument-list: It can be empty or non-empty as well. Arrow notation/lambda notation: It is used to link arguments-list and body of expression. Function-body: It contains expressions and statements for lambda expression.
🌐
Sourcecodeexamples
sourcecodeexamples.net › 2020 › 12 › java-lambda-expressions-multiple.html
Java Lambda Expressions Multiple Statements
March 22, 2024 - interface IAvarage{ double avg(int[] array); } public class JLEExampleMultipleStatements { public static void main(String[] args) { // without lambda expression, IAvarage implementation using anonymous class IAvarage avarage = new IAvarage() { @Override public double avg(int[] array) { double sum = 0; int arraySize = array.length; System.out.println("arraySize : " + arraySize); for (int i = 0; i < array.length; i++) { sum = sum + array[i]; } System.out.println("sum : " + sum); return (sum/ arraySize); } }; int[] array = {1,4,6,8,9}; System.out.println(avarage.avg(array)); // with a lambda expr
🌐
GeeksforGeeks
geeksforgeeks.org › java › block-lambda-expressions-in-java
Block Lambda Expressions in Java - GeeksforGeeks
July 14, 2026 - A Block Lambda Expression is a lambda expression whose body contains multiple statements enclosed within curly braces {}. Unlike single-expression lambdas, block lambdas can include local variables, loops, conditional statements, and return ...
Find elsewhere
🌐
Medium
medium.com › @nagarjun_nagesh › syntax-of-lambda-expressions-b7307f96a203
Syntax of Lambda Expressions. In the previous article, we introduced… | by Nagarjun (Arjun) Nagesh | Medium
February 23, 2024 - In this article, we explored the syntax of lambda expressions in Java, gaining a deep understanding of their various components. We saw how lambda expressions can represent functions with no parameters, one parameter, or multiple parameters. Additionally, we learned how lambda expressions can have multiple statements in their body and return values.
🌐
W3Schools
w3schools.com › java › java_lambda.asp
Java Lambda Expressions
The simplest lambda expression contains a single parameter and an expression: ... Simple expressions must return a value immediately. They cannot contain multiple statements, such as loops or if conditions.
🌐
Medium
medium.com › @lavishj77 › java-lambda-expressions-4ea3b8245196
Java Lambda Expressions. One of the big new feature added in… | by Lavish Jain | Medium
January 21, 2022 - 2. No need to mention argument ... an expression — that is, a statement or multiple statements — you’ll need to use the curly braces () -> {int a = 1; System.out.println(a);} (a,b) -> {int sum=a+b; return sum...
🌐
Oracle
docs.oracle.com › javase › tutorial › java › javaOO › lambdaexpressions.html
Lambda Expressions (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
public void printPersonsWithPredicate(List<Person> roster, Predicate<Person> tester) in Approach 6: Use Standard Functional Interfaces with Lambda Expressions · When the Java runtime invokes the method printPersons, it's expecting a data type of CheckPerson, so the lambda expression is of this type.
🌐
Stack Overflow
stackoverflow.com › questions › 40883527 › how-to-write-multiple-statements-in-lambda-expression-body-in-jsp-el
How to write multiple statements in lambda expression body in JSP EL - Stack Overflow
I know we can write: ${ factorial = n -> n==0? 1 : n * factorial(n-1); factorial(5) } But how do I write multiple statements in the lambda expression body in JSP EL e.g. what if I wanted to pr...
🌐
Medium
medium.com › @marcelogdomingues › java-lambda-expressions-techniques-for-advanced-developersava-lambda-expressions-techniques-for-c1d71c30bb1f
Java Lambda Expressions: Techniques for Advanced Developersava Lambda Expressions: Techniques for…
June 21, 2024 - Body: The body can be a single expression or a block of statements. If the body is a single expression, the return keyword and curly braces can be omitted. ... Before lambda expressions, implementing functional interfaces required creating anonymous inner classes. This approach often led to verbose and less readable code. Example: Sorting a List Using an Anonymous Inner Class · import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; public class TraditionalExample { public static void main(String[] args) { List<String> names = Arrays.asList("John", "Jane", "Jack", "Jill"); Collections.sort(names, new Comparator<String>() { @Override public int compare(String a, String b) { return a.compareTo(b); } }); for (String name : names) { System.out.println(name); } } }
🌐
Gunnargissel
gunnargissel.com › programming › programming › how to write a multiline lambda in java 8
How to Write a Multiline Lambda in Java 8 - Gunnar's blog
March 13, 2017 - A short example of how to make multiline lambda functions in Java 8 ... For the most part, single line lambda functions are all you need. ... Sometimes one line is not enough to express the complexity of the lambda.
🌐
DEV Community
dev.to › monknomo › how-to-write-a-multiline-lambda-in-java-8-2pl9
How to Write a Multiline Lambda in Java 8 - DEV Community
April 2, 2018 - The Java lambda syntax allows single line statements or statement blocks which can be arbitrarily long.
🌐
TechGuruSpeaks
techguruspeaks.com › java-lambda-expression
Java Lambda Expression - TechGuruSpeaks
April 25, 2020 - In a lambda expression, we assign input parameters (if there are any) on the left side of the lambda operator ->, and place the body of statements on the right side of lambda operator.
🌐
GeeksforGeeks
geeksforgeeks.org › java › lambda-expressions-java-8
Java - Lambda Expressions Parameters - GeeksforGeeks
When there is more than one statement, then these must be enclosed in curly brackets (a code block) and the return type of the anonymous function is the same as the type of the value returned within the code block, or void if nothing is returned.
Published: July 23, 2025
🌐
O'Reilly
oreilly.com › library › view › functional-programming-in › 9781941222690 › f_0088.html
Creating a Multiline Lambda Expression - Functional Programming in Java [Book]
February 19, 2014 - Creating a Multiline Lambda Expression​ FileWriterEAM.use(​"eam2.txt"​, writerEAM -> {​ writerEAM.writeStuff(​"how"​);​ writerEAM.writeStuff(​"sweet"​);​ ... - Selection from Functional Programming in Java [Book]
Author: Venkat Subramaniam
Published: 2014
Pages: 160
🌐
GeeksforGeeks
geeksforgeeks.org › java › lambda-expressions-java-8
Java Lambda Expressions - GeeksforGeeks
Two lambda expressions provide different implementations of this method: (a, b) -> a + b performs addition, while (a, b) -> a * b performs multiplication. The corresponding method calls produce 9 and 20.
Published: August 29, 2026