Class FunctionalInterfaceUtil

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

public final class FunctionalInterfaceUtil extends Object
Functional Interface Utility 函数式接口工具

Utilities for working with functional interfaces.

处理函数式接口的工具。

Features | 主要功能:

  • Functional interface detection - 函数式接口检测
  • Abstract method extraction - 抽象方法提取
  • SAM (Single Abstract Method) analysis - SAM分析

Usage Examples | 使用示例:

boolean isFunctional = FunctionalInterfaceUtil.isFunctionalInterface(Runnable.class);
Method sam = FunctionalInterfaceUtil.getSingleAbstractMethod(Function.class);

Security | 安全性:

  • Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
  • Null-safe: No (caller must ensure non-null arguments) - 空值安全: 否(调用方须确保非空参数)

Performance | 性能特性:

  • Time complexity: O(m) where m is the number of methods in the interface - 时间复杂度: O(m),m为接口中的方法数量
  • Space complexity: O(1) - 空间复杂度: O(1)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • 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 (SAM) of a functional interface 获取函数式接口的单一抽象方法(SAM)
      Parameters:
      clazz - the class | 类
      Returns:
      Optional of the SAM | SAM的Optional
    • getAbstractMethods

      public static List<Method> getAbstractMethods(Class<?> clazz)
      Gets all abstract methods of an interface 获取接口的所有抽象方法
      Parameters:
      clazz - the class | 类
      Returns:
      list of abstract methods | 抽象方法列表
    • getDefaultMethods

      public static List<Method> getDefaultMethods(Class<?> clazz)
      Gets default methods of an interface 获取接口的默认方法
      Parameters:
      clazz - the class | 类
      Returns:
      list of default methods | 默认方法列表
    • getStaticMethods

      public static List<Method> getStaticMethods(Class<?> clazz)
      Gets static methods of an interface 获取接口的静态方法
      Parameters:
      clazz - the class | 类
      Returns:
      list of static methods | 静态方法列表
    • getFunctionalMethodReturnType

      public static Class<?> getFunctionalMethodReturnType(Class<?> clazz)
      Gets the return type of the functional method 获取函数式方法的返回类型
      Parameters:
      clazz - the functional interface | 函数式接口
      Returns:
      the return type or null | 返回类型或null
    • getFunctionalMethodParameterTypes

      public static Class<?>[] getFunctionalMethodParameterTypes(Class<?> clazz)
      Gets the parameter types of the functional method 获取函数式方法的参数类型
      Parameters:
      clazz - the functional interface | 函数式接口
      Returns:
      array of parameter types | 参数类型数组
    • getFunctionalMethodArity

      public static int getFunctionalMethodArity(Class<?> clazz)
      Gets the arity (parameter count) of the functional method 获取函数式方法的元数(参数数量)
      Parameters:
      clazz - the functional interface | 函数式接口
      Returns:
      the arity | 元数
    • returnsVoid

      public static boolean returnsVoid(Class<?> clazz)
      Checks if functional interface returns void 检查函数式接口是否返回void
      Parameters:
      clazz - the functional interface | 函数式接口
      Returns:
      true if returns void | 如果返回void返回true
    • hasNoParameters

      public static boolean hasNoParameters(Class<?> clazz)
      Checks if functional interface has no parameters 检查函数式接口是否没有参数
      Parameters:
      clazz - the functional interface | 函数式接口
      Returns:
      true if no parameters | 如果没有参数返回true
    • classify

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