Lambda Expression:
Java 8 introduced many
features in its new version, amongst them stands lambda expressions. The way of
writing the methods have been changed. Especially for loop is more generalized.
Advantages of lambda:
1.
They add new syntax elements.
2.
Parallel processing can be done (more
detail in the parallelism section).
3.
It supports pipeline operations on data.
4.
Appending default functionality to the
method that is defined in interface, default functionality executes on the reference
of the interface method, surprisingly the method is not executed.
Implementation:
Implementation
of java includes two constructors:
1.
Lambda expression
2.
Functional interface.
Key points to remember:
1.
Lambda expression is anonymous method.
2.
This method don’t execute o its own,
rather used to execute a function or method that is defined in the functional
interface.
3.
They are called as ‘closures’.
4.
Lambda expression is redefined in the form
of anonymous classes.
5.
We can only use lambda expression if and
only if target type is known or specified.
Functional interface (Single
Abstract Method Type):
1. By
name it’s an interface that contains only one method, which is abstract.
2. It
defines the target type of the lambda expression.
Lambda expression:
1.
A new operator is introduced, operator is
called as ‘lambda operator’ or ‘arrow operator’. It is represented
by ‘->’. This sign is verbally
called as ‘goes to’ or ‘becomes’.
2.
The left side of the LE is used to specify
parameters and the right side is for lambda body.
3.
Lambda body is of two types:
1. Consisting
single expression.
2. Consisting
a block.
No comments:
Post a Comment