public class Main {
private long t, u;
private Long test(BinaryOperator<Long> b) {
return b.apply(t, u);
}
public static void main(String[] args) {
Main m = new Main();
m.t = 1; m.u = 2;
BinaryOperator<Long> b = (x, y) -> x + y;
System.out.println(m.test(b));
}
}
It is useless to pull it out alone. Lambda only defines the operation method of data, that is, it defines a function. Specifically where to use it, you need to define a method with a lambda expression (functional interface) as the parameter, and then call the actual operation of lambda (which function in the interface definition) inside the method, such as accept.
Lambda定义的并不是函数,它只是匿名类的缩写方式,其生成的还是一个对象。就如你的例子中,它生成的一个BinaryOperator<Long>Object, then it is an instance object of this class. How to use it is the same as how to use an object.
It is useless to pull it out alone. Lambda only defines the operation method of data, that is, it defines a function. Specifically where to use it, you need to define a method with a lambda expression (functional interface) as the parameter, and then call the actual operation of lambda (which function in the interface definition) inside the method, such as accept.
Lambda
定义的并不是函数,它只是匿名类的缩写方式,其生成的还是一个对象。就如你的例子中,它生成的一个BinaryOperator<Long>
Object, then it is an instance object of this class. How to use it is the same as how to use an object.