2. Java Lambda Expressions
ïLambda Expressions were added in Java 8.
ïA lambda expression is a short block of code
which takes in parameters and returns a value.
ïLambda expressions are similar to methods,
but they do not need a name and they can be
implemented right in the body of a method.
3. Java Lambda Expressions
ïJava Lambda Expressions are Javaâs first step into
Functional Programming.
ïIt is an Anonymous function that doesnât have a
name and doesnât belong to any class.
ïIt Provides a clear and concise way to represent a
method interface via an expression
ïIt provides the implementation of a Functional
Interface & Simplifies the software development.
4. Syntax
The simplest lambda expression
contains a single parameter and an
expression:
parameter -> expression
5. Syntax
To use more than one parameter, wrap
them in parentheses:
(parameter1, parameter2) -> expression
7. Functional Interface
ïFunctional Interface is an interface
that contains exactly one abstract
method.
ïIt can have any number of default or
static methods along with object class
methods.
ïJava provides pre-defined functional
interfaces to deal with the functional
programming.
ïRunnable, ActionListener,
Comparable are some of the
8. Here are just a few of the key
benefits to using lambda
expressions in Java:
Conciseness.
Reduction in code bloat.
Readability.
Elimination of shadow variables.
Encouragement of functional programming.
Code reuse.
Enhanced iterative syntax.
Simplified variable scope.