The lambda expression in Java 8 is a function interface, which is an interface with only one abstract method.
In Java, passing a behavior is accomplished by passing an object that represents a certain behavior, for example, to register an event listener for a button:
Button.addactionlistener (new ActionListener () { @Override publicvoid actionperformed (ActionEvent e) { System.out.println ("button clicked");} );
An actionperformed behavior is passed through an anonymous inner class. However, this way of passing behavior has to add some cumbersome boilerplate code, which is not easy enough.
In Java 8, you can write this:
Button.addactionlistener (Event-System.out.println ("button clicked"));
In fact, the LAMDBA expression type is a function interface, but in Java 8, the compiler can infer various kinds of information about the behavior of the lambda expression based on the context in which it is located.
A core set of function interfaces is provided in the JDK that can be used to pass the behavior.
A lambda expression is an anonymous method that passes the behavior as if it were data.
Java 8 lambda expression