A Quick Start Guide To Java Lambda Expression
Contents
Lambda expression is used as an implementation of an interface which has functional interface. Interface with only one abstract method is called functional interface.
Basics:
Runnable, ActionListener, Comparable are some of the examples of functional interfaces.
|
|
Now, Lets implement this
|
|
A Simple Use Case:
|
|
A Custom Implemention of Functional Interface, we want distance always in +ve
|
|
Lambda Syntax
| Argument List | Arrow Token | Body | | (int x, int y) | -> | x + y |
With Lambda Expression
|
|
- A Functional interface is a interface that has a single abstract method in it.
- Lambda expressions can only be used to implement functional interfaces
- They are just tools to provide a clear and concise way to represent one method interface.
Lambda expressions has paved the way for the Collection libraries making it easier to iterate through, filter, and extract data from a Collection. ( Stream, Collections )
For more info See: