Class TypeUtil
java.lang.Object
cloud.opencode.base.reflect.type.TypeUtil
Type Utility Class
类型工具类
Utility class providing common type operations including type resolution, primitive/wrapper conversion, and type string formatting.
提供常用类型操作的工具类,包括类型解析、原始/包装类型转换和类型字符串格式化。
Features | 主要功能:
- Raw type extraction - 原始类型提取
- Primitive/wrapper conversion - 原始/包装类型转换
- Type assignability checking - 类型可赋值检查
- Type string formatting - 类型字符串格式化
Usage Examples | 使用示例:
Class<?> raw = TypeUtil.getRawType(parameterizedType);
boolean assignable = TypeUtil.isAssignable(targetType, sourceType);
String formatted = TypeUtil.toString(genericType);
Security | 安全性:
- Thread-safe: Yes (stateless utility class, immutable maps) - 线程安全: 是(无状态工具类,不可变映射)
- Null-safe: No (caller must ensure non-null type arguments) - 空值安全: 否(调用方须确保非空类型参数)
Performance | 性能特性:
- Time complexity: O(1) for type lookups using immutable maps; toString() O(n) where n is the number of type arguments - 时间复杂度: 使用不可变映射的类型查找为 O(1);toString() 为 O(n),n为类型参数数量
- Space complexity: O(1) - 空间复杂度: O(1)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks if two types are equal considering type parameters 检查两个类型是否相等(考虑类型参数)static Type[]getActualTypeArguments(Type type) Gets actual type arguments from a parameterized type 从参数化类型获取实际类型参数static Class<?> getRawType(Type type) Gets the raw type from a Type 从Type获取原始类型static TypeVariable<?>[]getTypeParameters(Class<?> clazz) Gets type parameters from a class 从类获取类型参数static booleanisAssignableFrom(Type target, Type source) Checks if target type is assignable from source type 检查目标类型是否可从源类型赋值static booleanisPrimitive(Class<?> type) Checks if type is primitive 检查是否为原始类型static booleanChecks if type is wrapper 检查是否为包装类型static StringConverts Type to readable string 将Type转换为可读字符串static Class<?> Converts wrapper to primitive 将包装类型转换为原始类型static Class<?> Converts primitive to wrapper 将原始类型转换为包装类型
-
Method Details
-
getRawType
-
isPrimitive
Checks if type is primitive 检查是否为原始类型- Parameters:
type- the type | 类型- Returns:
- true if primitive | 如果是原始类型返回true
-
isWrapper
Checks if type is wrapper 检查是否为包装类型- Parameters:
type- the type | 类型- Returns:
- true if wrapper | 如果是包装类型返回true
-
wrap
-
unwrap
-
isAssignableFrom
-
toString
-
getTypeParameters
Gets type parameters from a class 从类获取类型参数- Parameters:
clazz- the class | 类- Returns:
- array of type variables | 类型变量数组
-
getActualTypeArguments
-
equals
-