Class LambdaUtil

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

public final class LambdaUtil extends Object
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 Details

    • getSerializedLambda

      public static SerializedLambda getSerializedLambda(Serializable lambda)
      Gets SerializedLambda from a serializable lambda 从可序列化lambda获取SerializedLambda

      Note: 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

      public static Optional<SerializedLambda> getSerializedLambdaSafe(Serializable lambda)
      Gets SerializedLambda safely 安全获取SerializedLambda
      Parameters:
      lambda - the lambda | lambda
      Returns:
      Optional of SerializedLambda | SerializedLambda的Optional
    • getImplClassName

      public static String getImplClassName(Serializable lambda)
      Gets the implementing class name 获取实现类名
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the class name | 类名
    • getImplClass

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

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

      public static String getImplMethodSignature(Serializable lambda)
      Gets the implementing method signature 获取实现方法签名
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the method signature | 方法签名
    • getFunctionalInterfaceClassName

      public static String getFunctionalInterfaceClassName(Serializable lambda)
      Gets the functional interface class name 获取函数式接口类名
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the interface class name | 接口类名
    • getFunctionalInterfaceMethodName

      public static String getFunctionalInterfaceMethodName(Serializable lambda)
      Gets the functional interface method name 获取函数式接口方法名
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the method name | 方法名
    • getCapturedArgCount

      public static int getCapturedArgCount(Serializable lambda)
      Gets the captured argument count 获取捕获参数数量
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the count | 数量
    • getCapturedArg

      public static Object getCapturedArg(Serializable lambda, int index)
      Gets a captured argument 获取捕获参数
      Parameters:
      lambda - the lambda | lambda
      index - the index | 索引
      Returns:
      the captured argument | 捕获参数
    • 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
    • getImplMethodKind

      public static int getImplMethodKind(Serializable lambda)
      Gets the implementation method kind 获取实现方法种类
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the method kind | 方法种类
    • isStaticMethodReference

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

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

      public static String extractPropertyName(Serializable lambda)
      Extracts property name from getter method reference 从getter方法引用提取属性名
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the property name | 属性名
    • extractPropertyNameFromMethodName

      public static String extractPropertyNameFromMethodName(String methodName)
      Extracts property name from method name 从方法名提取属性名
      Parameters:
      methodName - the method name | 方法名
      Returns:
      the property name | 属性名
    • getImplMethod

      public static Method getImplMethod(Serializable lambda)
      Gets the implementation method 获取实现方法
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the method or null | 方法或null
    • getImplMethodSafe

      public static Optional<Method> getImplMethodSafe(Serializable lambda)
      Gets the implementation method safely 安全获取实现方法
      Parameters:
      lambda - the lambda | lambda
      Returns:
      Optional of method | 方法的Optional
    • toMethodHandle

      public static MethodHandle toMethodHandle(Serializable lambda)
      Creates a MethodHandle for the implementation method 为实现方法创建MethodHandle
      Parameters:
      lambda - the lambda | lambda
      Returns:
      the MethodHandle | MethodHandle
    • toMethodHandleSafe

      public static Optional<MethodHandle> toMethodHandleSafe(Serializable lambda)
      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