Class OpenLambda
java.lang.Object
cloud.opencode.base.reflect.lambda.OpenLambda
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA consumer that can throw checked exceptions 可以抛出检查异常的消费者static interfaceA function that can throw checked exceptions 可以抛出检查异常的函数static interfaceA supplier that can throw checked exceptions 可以抛出检查异常的提供者 -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Predicate<T> Creates a predicate that always returns false 创建总是返回false的谓词static <T> Predicate<T> Creates a predicate that always returns true 创建总是返回true的谓词static <T> RunnableCreates a runnable from a consumer and value 从消费者和值创建可运行对象static <T,R> Supplier <R> Creates a supplier from a function and input 从函数和输入创建提供者Classifies a functional interface 分类函数式接口static <T> Supplier<T> constant(T value) Creates a supplier from a value 从值创建提供者static Class<?> getImplClass(Serializable lambda) Gets the implementation class 获取实现类getImplMethod(Serializable lambda) Gets the implementation method of a lambda 获取lambda的实现方法static StringgetImplMethodName(Serializable lambda) Gets the implementation method name 获取实现方法名static LambdaInfogetInfo(Serializable lambda) Extracts metadata from a serializable lambda 从可序列化lambda提取元数据static <T,R> Class <?> getPropertyClass(SerializableFunction<T, R> getter) Gets the property class from a getter 从getter获取属性类static <T,R> String getPropertyName(SerializableFunction<T, R> getter) Extracts property name from a getter method reference 从getter方法引用提取属性名static <T> StringgetPropertyNameFromSetter(SerializableConsumer<T> setter) Extracts property name from a setter method reference 从setter方法引用提取属性名getSingleAbstractMethod(Class<?> clazz) Gets the single abstract method of a functional interface 获取函数式接口的单一抽象方法static <T> Function<T, T> identity()Creates an identity function 创建恒等函数static booleanisFunctionalInterface(Class<?> clazz) Checks if a class is a functional interface 检查类是否为函数式接口static booleanisMethodReference(Serializable lambda) Checks if lambda is a method reference 检查lambda是否为方法引用static <T> Consumer<T> noOp()Creates a no-op consumer 创建空操作消费者static <T> Consumer<T> safe(OpenLambda.ThrowingConsumer<T> consumer) Safely wraps a throwing consumer 安全包装可抛出异常的消费者static <T,R> Function <T, R> safe(OpenLambda.ThrowingFunction<T, R> function) Safely wraps a throwing function 安全包装可抛出异常的函数static <T> Supplier<T> safe(OpenLambda.ThrowingSupplier<T> supplier) Safely wraps a throwing supplier 安全包装可抛出异常的提供者
-
Method Details
-
getInfo
Extracts metadata from a serializable lambda 从可序列化lambda提取元数据- Parameters:
lambda- the lambda | lambda- Returns:
- the LambdaInfo | LambdaInfo
-
getImplMethod
Gets the implementation method of a lambda 获取lambda的实现方法- Parameters:
lambda- the lambda | lambda- Returns:
- Optional of the method | 方法的Optional
-
getImplMethodName
Gets the implementation method name 获取实现方法名- Parameters:
lambda- the lambda | lambda- Returns:
- the method name | 方法名
-
getImplClass
Gets the implementation class 获取实现类- Parameters:
lambda- the lambda | lambda- Returns:
- the implementation class | 实现类
-
isMethodReference
Checks if lambda is a method reference 检查lambda是否为方法引用- Parameters:
lambda- the lambda | lambda- Returns:
- true if method reference | 如果是方法引用返回true
-
getPropertyName
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
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
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
Checks if a class is a functional interface 检查类是否为函数式接口- Parameters:
clazz- the class | 类- Returns:
- true if functional interface | 如果是函数式接口返回true
-
getSingleAbstractMethod
-
classify
Classifies a functional interface 分类函数式接口- Parameters:
clazz- the class | 类- Returns:
- the category | 类别
-
constant
Creates a supplier from a value 从值创建提供者- Type Parameters:
T- the type | 类型- Parameters:
value- the value | 值- Returns:
- the supplier | 提供者
-
alwaysTrue
Creates a predicate that always returns true 创建总是返回true的谓词- Type Parameters:
T- the type | 类型- Returns:
- the predicate | 谓词
-
alwaysFalse
Creates a predicate that always returns false 创建总是返回false的谓词- Type Parameters:
T- the type | 类型- Returns:
- the predicate | 谓词
-
identity
Creates an identity function 创建恒等函数- Type Parameters:
T- the type | 类型- Returns:
- the identity function | 恒等函数
-
noOp
Creates a no-op consumer 创建空操作消费者- Type Parameters:
T- the type | 类型- Returns:
- the no-op consumer | 空操作消费者
-
bind
-
bind
-
safe
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
Safely wraps a throwing consumer 安全包装可抛出异常的消费者- Type Parameters:
T- the input type | 输入类型- Parameters:
consumer- the throwing consumer | 可抛出异常的消费者- Returns:
- the safe consumer | 安全消费者
-
safe
Safely wraps a throwing supplier 安全包装可抛出异常的提供者- Type Parameters:
T- the result type | 结果类型- Parameters:
supplier- the throwing supplier | 可抛出异常的提供者- Returns:
- the safe supplier | 安全提供者
-