新建函数接口
Operation
@FunctionalInterface
public interface Operation<R, T> {
R operator (T t1, T t2);
}
在测试类中实现
public class TestDemo {
@Test
public void testOperator() {
System.out.println(operator(2, 5, (x, y) -> {
return x * y;
}));
}
private static Integer operator(Integer x, Integer y,
Operation<Integer, Integer> operation) {
return operation.operator(x, y);
}
}