Class LambdaFactory

java.lang.Object
org.aoju.bus.core.lang.function.LambdaFactory

public class LambdaFactory extends Object
以类似反射的方式动态创建Lambda,在性能上有一定优势,同时避免每次调用Lambda时创建匿名内部类
Since:
Java 17+
Author:
Kimi Liu
  • Method Details

    • build

      public static <F> F build(Class<F> functionInterfaceType, Class<?> methodClass, String methodName, Class<?>... paramTypes)
      构建Lambda
      
       class Something {
           private Long id;
           private String name;
           // ... 省略GetterSetter方法
       }
       Function<Something, Long> getIdFunction = LambdaFactory.buildLambda(Function.class, Something.class, "getId");
       XConsumer<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

      public static <F> F build(Class<F> functionInterfaceType, Method method)
      构建Lambda
      Type Parameters:
      F - Function类型
      Parameters:
      functionInterfaceType - 接受Lambda的函数式接口类型
      method - 方法对象
      Returns:
      接受Lambda的函数式接口对象