It does not make sense to say Lambda allows functions to be arguments to a method.

Lambda expressions represent the implementation class entities of the target interface

Runnable r = () -> {system.out.println (" here is a child thread "); };Copy the code

The lambda expression representation here is the anonymous implementation class of the Runnable interface, and the run method prints a statement

The target interface refers to the interface that is required to be passed in as a method parameter
Collections.sort(new ArrayList<>(), (o1, o2) -> 1);
Copy the code

The lambda expression is the implementation class entity of the Comparator interface that the sort method requires to pass in

The target interface does not specify which type directly, so lambda expressions cannot be used if the following overloads exist
public void testFuntional(Interface1 interface1) {}
public void testFuntional(Interface2 interface2) {}
Copy the code

If interface 1 and interface 2 are both functional interfaces and you call the testFunctional method somewhere, passing arguments through lambda expressions is not feasible because the compiler cannot tell which interface’s implementation class the lambda expression is.

To sum up:

① Lambda expressions represent the implementation class entity of the target interface. This interface is not necessarily qualified with @functionalInterface, but has one and only abstract method (overriding methods do not count). Its purpose is to “simplify the implementation class writing of interfaces with only one abstract method”. If you have only one abstract method, then I have described this method clearly and expressed the meaning is not clear?

② the @functionalInterface annotation acts as an identifier and syntax constraint similar to @Override

If there is any mistake, welcome to exchange correction