In the book OCP Study Guide there is this example about a Comparator that can be initialized in two ways. The first is via an anonymous class like this:
<
The interface Comparator
is a Functional Interface, this means this interface can only contains one abstract method.
Then you can use lambda expression to define the implementation of this abstract method, basically (d1,d2) -> d1.getWeight() - d2.getWeight();
is the implementation of the abstract method int compare(T o1, T o2);
.
As a functionnal Interface contains only one abstract method, you can use lambda expression to define the implementation of such interface