Class LambdaUtil
java.lang.Object
cloud.opencode.base.reflect.lambda.LambdaUtil
Lambda Utility Class
Lambda工具类
Provides low-level lambda operation utilities with caching.
提供带缓存的底层lambda操作工具。
Features | 主要功能:
- SerializedLambda extraction with caching - 带缓存的SerializedLambda提取
- Implementation method resolution - 实现方法解析
Usage Examples | 使用示例:
SerializedLambda sl = LambdaUtil.getSerializedLambda(lambda);
String methodName = sl.getImplMethodName();
Security | 安全性:
- Thread-safe: Yes (uses ConcurrentHashMap for caching) - 线程安全: 是(使用ConcurrentHashMap缓存)
- Null-safe: No (caller must ensure non-null lambda) - 空值安全: 否(调用方须确保非空lambda)
Performance | 性能特性:
- Time complexity: O(1) for cached lookups; O(1) for first SerializedLambda extraction via reflection - 时间复杂度: 缓存命中时 O(1);首次通过反射提取 SerializedLambda 为 O(1)
- Space complexity: O(1) per cached lambda class entry - 空间复杂度: O(1),每个缓存 lambda 类条目
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears lambda cache (no-op, caching removed) 清除lambda缓存(空操作,缓存已移除)static StringextractPropertyName(Serializable lambda) Extracts property name from getter method reference 从getter方法引用提取属性名static StringextractPropertyNameFromMethodName(String methodName) Extracts property name from method name 从方法名提取属性名static intGets cache size (always returns 0, caching removed) 获取缓存大小(始终返回0,缓存已移除)static ObjectgetCapturedArg(Serializable lambda, int index) Gets a captured argument 获取捕获参数static intgetCapturedArgCount(Serializable lambda) Gets the captured argument count 获取捕获参数数量static StringGets the functional interface class name 获取函数式接口类名static StringGets the functional interface method name 获取函数式接口方法名static Class<?> getImplClass(Serializable lambda) Gets the implementing class 获取实现类static StringgetImplClassName(Serializable lambda) Gets the implementing class name 获取实现类名static MethodgetImplMethod(Serializable lambda) Gets the implementation method 获取实现方法static intgetImplMethodKind(Serializable lambda) Gets the implementation method kind 获取实现方法种类static StringgetImplMethodName(Serializable lambda) Gets the implementing method name 获取实现方法名getImplMethodSafe(Serializable lambda) Gets the implementation method safely 安全获取实现方法static StringgetImplMethodSignature(Serializable lambda) Gets the implementing method signature 获取实现方法签名static SerializedLambdagetSerializedLambda(Serializable lambda) Gets SerializedLambda from a serializable lambda 从可序列化lambda获取SerializedLambdastatic Optional<SerializedLambda> getSerializedLambdaSafe(Serializable lambda) Gets SerializedLambda safely 安全获取SerializedLambdastatic booleanisConstructorReference(Serializable lambda) Checks if the method reference is a constructor reference 检查方法引用是否为构造器引用static booleanisMethodReference(Serializable lambda) Checks if lambda is a method reference 检查lambda是否为方法引用static booleanisStaticMethodReference(Serializable lambda) Checks if the method reference is static 检查方法引用是否为静态static MethodHandletoMethodHandle(Serializable lambda) Creates a MethodHandle for the implementation method 为实现方法创建MethodHandlestatic Optional<MethodHandle> toMethodHandleSafe(Serializable lambda) Creates a MethodHandle safely 安全创建MethodHandle
-
Method Details
-
getSerializedLambda
Gets SerializedLambda from a serializable lambda 从可序列化lambda获取SerializedLambdaNote: No caching is used because different lambda instances of the same class may capture different values, making class-based caching incorrect.
注意:不使用缓存,因为同一类的不同lambda实例可能捕获不同的值, 基于类的缓存是不正确的。
- Parameters:
lambda- the lambda | lambda- Returns:
- the SerializedLambda | SerializedLambda
-
getSerializedLambdaSafe
Gets SerializedLambda safely 安全获取SerializedLambda- Parameters:
lambda- the lambda | lambda- Returns:
- Optional of SerializedLambda | SerializedLambda的Optional
-
getImplClassName
Gets the implementing class name 获取实现类名- Parameters:
lambda- the lambda | lambda- Returns:
- the class name | 类名
-
getImplClass
Gets the implementing class 获取实现类- Parameters:
lambda- the lambda | lambda- Returns:
- the class | 类
-
getImplMethodName
Gets the implementing method name 获取实现方法名- Parameters:
lambda- the lambda | lambda- Returns:
- the method name | 方法名
-
getImplMethodSignature
Gets the implementing method signature 获取实现方法签名- Parameters:
lambda- the lambda | lambda- Returns:
- the method signature | 方法签名
-
getFunctionalInterfaceClassName
Gets the functional interface class name 获取函数式接口类名- Parameters:
lambda- the lambda | lambda- Returns:
- the interface class name | 接口类名
-
getFunctionalInterfaceMethodName
Gets the functional interface method name 获取函数式接口方法名- Parameters:
lambda- the lambda | lambda- Returns:
- the method name | 方法名
-
getCapturedArgCount
Gets the captured argument count 获取捕获参数数量- Parameters:
lambda- the lambda | lambda- Returns:
- the count | 数量
-
getCapturedArg
Gets a captured argument 获取捕获参数- Parameters:
lambda- the lambda | lambdaindex- the index | 索引- Returns:
- the captured argument | 捕获参数
-
isMethodReference
Checks if lambda is a method reference 检查lambda是否为方法引用- Parameters:
lambda- the lambda | lambda- Returns:
- true if method reference | 如果是方法引用返回true
-
getImplMethodKind
Gets the implementation method kind 获取实现方法种类- Parameters:
lambda- the lambda | lambda- Returns:
- the method kind | 方法种类
-
isStaticMethodReference
Checks if the method reference is static 检查方法引用是否为静态- Parameters:
lambda- the lambda | lambda- Returns:
- true if static | 如果是静态返回true
-
isConstructorReference
Checks if the method reference is a constructor reference 检查方法引用是否为构造器引用- Parameters:
lambda- the lambda | lambda- Returns:
- true if constructor | 如果是构造器返回true
-
extractPropertyName
Extracts property name from getter method reference 从getter方法引用提取属性名- Parameters:
lambda- the lambda | lambda- Returns:
- the property name | 属性名
-
extractPropertyNameFromMethodName
-
getImplMethod
Gets the implementation method 获取实现方法- Parameters:
lambda- the lambda | lambda- Returns:
- the method or null | 方法或null
-
getImplMethodSafe
Gets the implementation method safely 安全获取实现方法- Parameters:
lambda- the lambda | lambda- Returns:
- Optional of method | 方法的Optional
-
toMethodHandle
Creates a MethodHandle for the implementation method 为实现方法创建MethodHandle- Parameters:
lambda- the lambda | lambda- Returns:
- the MethodHandle | MethodHandle
-
toMethodHandleSafe
Creates a MethodHandle safely 安全创建MethodHandle- Parameters:
lambda- the lambda | lambda- Returns:
- Optional of MethodHandle | MethodHandle的Optional
-
clearCache
public static void clearCache()Clears lambda cache (no-op, caching removed) 清除lambda缓存(空操作,缓存已移除) -
getCacheSize
public static int getCacheSize()Gets cache size (always returns 0, caching removed) 获取缓存大小(始终返回0,缓存已移除)- Returns:
- always 0 | 始终为0
-