In JDK 8 a LAMBDA Expression is a way of defining the anonymous functions. Simple example is as follows.
Consumer<String> consumer = (x) -> System.out.print(x);
Now calling consumer.accept(" Hey There !"); and it will apply the string parameter to the body of the anonymous function.
Result: Hey There !
We can think of it as a function defined in two parts:
- The right part of the expression is the body of the function
- The signature of the function is defined in a Functional Interface, in this case the
Consumer<T>interface (more about Functional Interfaces below.
Lambda Expression vs Anonymous classes.
Need to update ....
0 comments:
Post a Comment