Lambda Expressions Syntax

Description

The general syntax for using lambda expressions is

(Parameters) -> { Body }

-> separates parameters and lambda expression body.

The parameters are enclosed in parentheses which is the same way as for methods while the lambda expression body is a block of code enclosed in braces.

Note

The lambda expression body may have local variables, statements. We can use break, continue, and return in lambda expression body. We can even throw exceptions out of lambda expression body.

A lambda expression does not have a name since it represents anonymous inner class.

The return type of a lambda expression is inferred by the compiler.

A lambda expression cannot have a throws clause like a method.

A lambda expression cannot be generic while the generic is defined in the functional interface.





















Home »
  Java Lambda »
    Java Lambda Tutorial »




Java Lambda Tutorial