Develop apps with Stericsson

Lambda expressions in Java – what they are, why they are needed and what they look like

Energistically cultivate inexpensive processes after go forward materials. Quickly re-engineer extensive testing procedures whereas orthogonal portals. Quickly visualize synergistic functionalities without error-free outsourcing. Completely parallel task multimedia based platforms for visionary convergence. Enthusiastically target global initiatives.

Lambda expressions or anonymous functions are blocks of code with parameters that can be called from elsewhere in the program. They are called anonymous because, unlike functions, they have no names. The word “lambda” comes from the lambda calculus, coined by Professor Alonzo Church. He used the Greek letter lambda (λ) to mark the parameters.
Lambda expressions in Java

Present since version 8.
They are anonymous classes that implement a functional interface method.
Only have access to final (or effectively final) variables from the enveloping scope (for thread safety).
They cannot return a value in some branches, and not in others.
Allows you to reduce the amount of code and increase its readability.

Examples of syntax for lambda expressions in Java

Lambda expressions in Java consist of parameters and an arrow -> that separates the body of the function. The parentheses are needed if the parameters are 0 or more than one. The return keyword is optional for single-line lambdas.

Sebastian Liremann

Add comment