自定义接口
/**
*
* @param <R> return
* @param <T> 参数
*/
@FunctionalInterface
public interface OperFunction<R,T> {
R operator(T t1,T t2);
}
实现
public static Integer operator(Integer x, Integer y, OperFunction<Integer, Integer> of) {
return of.operator(x, y);
}
调用
public static void main(String[] args) {
//第1种书写方式
Integer operator1 = operator(20, 5, (x, y) -> {
return x * y;
});
//第2种书写方式
Integer operator = operator(20, 5, (x, y) -> x * y);
//第3种书写方式
operator(20,5,(Integer x,Integer y)->{
return x*y;
});
}