Class TypeVariableUtil

java.lang.Object
cloud.opencode.base.reflect.type.TypeVariableUtil

public final class TypeVariableUtil extends Object
Type Variable Utility Class 类型变量工具类

Utility class for working with type variables in generics.

用于处理泛型中类型变量的工具类。

Features | 主要功能:

  • Type variable lookup by name - 按名称查找类型变量
  • Type variable bounds extraction - 类型变量边界提取
  • Type parameter analysis - 类型参数分析

Usage Examples | 使用示例:

TypeVariable<?> tv = TypeVariableUtil.getTypeVariable(MyClass.class, "T");
Type[] bounds = TypeVariableUtil.getBounds(tv);

Security | 安全性:

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

Performance | 性能特性:

  • Time complexity: O(p) where p is the number of type parameters on the class - 时间复杂度: O(p),p为类上的类型参数数量
  • 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

    • getTypeVariable

      public static TypeVariable<?> getTypeVariable(Class<?> clazz, String name)
      Gets type variable by name from a class 从类按名称获取类型变量
      Parameters:
      clazz - the class | 类
      name - the type variable name | 类型变量名
      Returns:
      the type variable or null | 类型变量或null
    • getTypeVariableNames

      public static List<String> getTypeVariableNames(Class<?> clazz)
      Gets all type variable names from a class 从类获取所有类型变量名
      Parameters:
      clazz - the class | 类
      Returns:
      list of type variable names | 类型变量名列表
    • getBounds

      public static Type[] getBounds(TypeVariable<?> typeVariable)
      Gets the bounds of a type variable 获取类型变量的边界
      Parameters:
      typeVariable - the type variable | 类型变量
      Returns:
      array of bounds | 边界数组
    • hasBounds

      public static boolean hasBounds(TypeVariable<?> typeVariable)
      Checks if a type variable has non-Object bounds 检查类型变量是否有非Object边界
      Parameters:
      typeVariable - the type variable | 类型变量
      Returns:
      true if has bounds | 如果有边界返回true
    • getUpperBound

      public static Type getUpperBound(TypeVariable<?> typeVariable)
      Gets the upper bound of a type variable 获取类型变量的上界
      Parameters:
      typeVariable - the type variable | 类型变量
      Returns:
      the upper bound or Object.class | 上界或Object.class
    • getRawUpperBound

      public static Class<?> getRawUpperBound(TypeVariable<?> typeVariable)
      Gets the raw upper bound class of a type variable 获取类型变量的原始上界类
      Parameters:
      typeVariable - the type variable | 类型变量
      Returns:
      the raw upper bound class | 原始上界类
    • containsTypeVariable

      public static boolean containsTypeVariable(Type type)
      Checks if a type contains type variables 检查类型是否包含类型变量
      Parameters:
      type - the type | 类型
      Returns:
      true if contains type variables | 如果包含类型变量返回true
    • collectTypeVariables

      public static Set<TypeVariable<?>> collectTypeVariables(Type type)
      Collects all type variables from a type 从类型收集所有类型变量
      Parameters:
      type - the type | 类型
      Returns:
      set of type variables | 类型变量集合
    • getTypeArgumentsByName

      public static Map<String,Type> getTypeArgumentsByName(Type type)
      Creates a map of type variable names to their Types from a parameterized type 从参数化类型创建类型变量名到Type的映射
      Parameters:
      type - the parameterized type | 参数化类型
      Returns:
      map of names to types | 名称到类型的映射