Class LambdaFactory
java.lang.Object
org.miaixz.bus.core.center.function.LambdaFactory
以类似反射的方式动态创建Lambda,在性能上有一定优势,同时避免每次调用Lambda时创建匿名内部类
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Method Summary
-
Method Details
-
build
public static <F> F build(Class<F> functionInterfaceType, Class<?> methodClass, String methodName, Class<?>... paramTypes) 构建Lambdaclass Something { private Long data; private String name; // ... 省略GetterSetter方法 } Function<Something, Long> getIdFunction = LambdaFactory.buildLambda(Function.class, Something.class, "getId"); BiConsumer<Something, String> setNameConsumer = LambdaFactory.buildLambda(BiConsumer.class, Something.class, "setName", String.class);- Type Parameters:
F- Function类型- Parameters:
functionInterfaceType- 接受Lambda的函数式接口类型methodClass- 声明方法的类的类型methodName- 方法名称paramTypes- 方法参数数组- Returns:
- 接受Lambda的函数式接口对象
-
build
根据提供的方法或构造对象,构建对应的Lambda函数 调用函数相当于执行对应的方法或构造- Type Parameters:
F- Function类型- Parameters:
functionInterfaceType- 接受Lambda的函数式接口类型executable- 方法对象,支持构造器- Returns:
- 接受Lambda的函数式接口对象
-