Class OpenLambda

java.lang.Object
cloud.opencode.base.reflect.lambda.OpenLambda

public final class OpenLambda extends Object
Lambda Facade Entry Class Lambda门面入口类

Provides common lambda operations API.

提供常用lambda操作API。

Features | 主要功能:

  • Lambda metadata extraction - Lambda元数据提取
  • Method reference detection - 方法引用检测
  • Functional interface utilities - 函数式接口工具

Usage Examples | 使用示例:

// Extract lambda info
LambdaInfo info = OpenLambda.getInfo((SerializableFunction<User, String>) User::getName);

// Get implementation method
Method method = OpenLambda.getImplMethod((SerializableFunction<User, String>) User::getName);

// Get field name from getter reference
String fieldName = OpenLambda.getFieldName((SerializableFunction<User, String>) User::getName);

Security | 安全性:

  • Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
  • Null-safe: No (caller must ensure non-null lambda) - 空值安全: 否(调用方须确保非空lambda)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • getInfo

      public static LambdaInfo getInfo(Serializable lambda)
      Extracts metadata from a serializable lambda 从可序列化lambda提取元数据
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the LambdaInfo | LambdaInfo
    • getImplMethod

      public static Optional<Method> getImplMethod(Serializable lambda)
      Gets the implementation method of a lambda 获取lambda的实现方法
      Parameters:
      lambda - the lambda | lambda
      Returns:
      Optional of the method | 方法的Optional
    • getImplMethodName

      public static String getImplMethodName(Serializable lambda)
      Gets the implementation method name 获取实现方法名
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the method name | 方法名
    • getImplClass

      public static Class<?> getImplClass(Serializable lambda)
      Gets the implementation class 获取实现类
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the implementation class | 实现类
    • isMethodReference

      public static boolean isMethodReference(Serializable lambda)
      Checks if lambda is a method reference 检查lambda是否为方法引用
      Parameters:
      lambda - the lambda | lambda
      Returns:
      true if method reference | 如果是方法引用返回true
    • getPropertyName

      public static <T,R> String getPropertyName(SerializableFunction<T,R> getter)
      Extracts property name from a getter method reference 从getter方法引用提取属性名
      Type Parameters:
      T - the bean type | bean类型
      R - the property type | 属性类型
      Parameters:
      getter - the getter method reference | getter方法引用
      Returns:
      the property name | 属性名
    • getPropertyNameFromSetter

      public static <T> String getPropertyNameFromSetter(SerializableConsumer<T> setter)
      Extracts property name from a setter method reference 从setter方法引用提取属性名
      Type Parameters:
      T - the bean type | bean类型
      Parameters:
      setter - the setter method reference | setter方法引用
      Returns:
      the property name | 属性名
    • getPropertyClass

      public static <T,R> Class<?> getPropertyClass(SerializableFunction<T,R> getter)
      Gets the property class from a getter 从getter获取属性类
      Type Parameters:
      T - the bean type | bean类型
      R - the property type | 属性类型
      Parameters:
      getter - the getter | getter
      Returns:
      the property class | 属性类
    • isFunctionalInterface

      public static boolean isFunctionalInterface(Class<?> clazz)
      Checks if a class is a functional interface 检查类是否为函数式接口
      Parameters:
      clazz - the class | 类
      Returns:
      true if functional interface | 如果是函数式接口返回true
    • getSingleAbstractMethod

      public static Optional<Method> getSingleAbstractMethod(Class<?> clazz)
      Gets the single abstract method of a functional interface 获取函数式接口的单一抽象方法
      Parameters:
      clazz - the class | 类
      Returns:
      Optional of the SAM | SAM的Optional
    • classify

      public static FunctionalInterfaceUtil.FunctionalCategory classify(Class<?> clazz)
      Classifies a functional interface 分类函数式接口
      Parameters:
      clazz - the class | 类
      Returns:
      the category | 类别
    • constant

      public static <T> Supplier<T> constant(T value)
      Creates a supplier from a value 从值创建提供者
      Type Parameters:
      T - the type | 类型
      Parameters:
      value - the value | 值
      Returns:
      the supplier | 提供者
    • alwaysTrue

      public static <T> Predicate<T> alwaysTrue()
      Creates a predicate that always returns true 创建总是返回true的谓词
      Type Parameters:
      T - the type | 类型
      Returns:
      the predicate | 谓词
    • alwaysFalse

      public static <T> Predicate<T> alwaysFalse()
      Creates a predicate that always returns false 创建总是返回false的谓词
      Type Parameters:
      T - the type | 类型
      Returns:
      the predicate | 谓词
    • identity

      public static <T> Function<T,T> identity()
      Creates an identity function 创建恒等函数
      Type Parameters:
      T - the type | 类型
      Returns:
      the identity function | 恒等函数
    • noOp

      public static <T> Consumer<T> noOp()
      Creates a no-op consumer 创建空操作消费者
      Type Parameters:
      T - the type | 类型
      Returns:
      the no-op consumer | 空操作消费者
    • bind

      public static <T> Runnable bind(Consumer<T> consumer, T value)
      Creates a runnable from a consumer and value 从消费者和值创建可运行对象
      Type Parameters:
      T - the type | 类型
      Parameters:
      consumer - the consumer | 消费者
      value - the value | 值
      Returns:
      the runnable | 可运行对象
    • bind

      public static <T,R> Supplier<R> bind(Function<T,R> function, T input)
      Creates a supplier from a function and input 从函数和输入创建提供者
      Type Parameters:
      T - the input type | 输入类型
      R - the result type | 结果类型
      Parameters:
      function - the function | 函数
      input - the input | 输入
      Returns:
      the supplier | 提供者
    • safe

      public static <T,R> Function<T,R> safe(OpenLambda.ThrowingFunction<T,R> function)
      Safely wraps a throwing function 安全包装可抛出异常的函数
      Type Parameters:
      T - the input type | 输入类型
      R - the result type | 结果类型
      Parameters:
      function - the throwing function | 可抛出异常的函数
      Returns:
      the safe function | 安全函数
    • safe

      public static <T> Consumer<T> safe(OpenLambda.ThrowingConsumer<T> consumer)
      Safely wraps a throwing consumer 安全包装可抛出异常的消费者
      Type Parameters:
      T - the input type | 输入类型
      Parameters:
      consumer - the throwing consumer | 可抛出异常的消费者
      Returns:
      the safe consumer | 安全消费者
    • safe

      public static <T> Supplier<T> safe(OpenLambda.ThrowingSupplier<T> supplier)
      Safely wraps a throwing supplier 安全包装可抛出异常的提供者
      Type Parameters:
      T - the result type | 结果类型
      Parameters:
      supplier - the throwing supplier | 可抛出异常的提供者
      Returns:
      the safe supplier | 安全提供者