Class TypeUtil
java.lang.Object
cloud.opencode.base.core.convert.TypeUtil
Type Utility Class - Type checking, conversion and metadata operations
类型工具类 - 类型检查、转换和元数据操作
Provides utilities for type checking, primitive/wrapper conversion and type classification.
提供类型检查、原始/包装类型转换和类型分类功能。
Features | 主要功能:
- Type checking (isPrimitive, isWrapper, isNumber, isDate) - 类型检查
- Primitive/Wrapper conversion (wrap, unwrap) - 原始/包装类型转换
- Generic type extraction (getTypeArgument) - 泛型类型提取
- Type compatibility checking (isAssignable) - 类型兼容性检查
Usage Examples | 使用示例:
// Type checking - 类型检查
boolean isPrim = TypeUtil.isPrimitive(int.class); // true
boolean isNum = TypeUtil.isNumber(Integer.class); // true
// Wrapper conversion - 包装类型转换
Class<?> wrapper = TypeUtil.wrap(int.class); // Integer.class
Class<?> prim = TypeUtil.unwrap(Integer.class); // int.class
Security | 安全性:
- Thread-safe: Yes (immutable constants) - 线程安全: 是 (不可变常量)
- Null-safe: Yes - 空值安全: 是
Performance | 性能特性:
- Time complexity: O(1) for type resolution - 类型解析 O(1)
- Space complexity: O(1) - O(1)
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TConverts the type 类型转换static <T> Optional<T> convertOptional(Object value, Class<T> targetType) 安全类型转换,返回 Optionalstatic <T> TgetDefaultValue(Class<T> clazz) Gets the default value for the type 获取类型的默认值static TypegetFieldGenericType(Field field) Gets the generic type of a field 获取字段的泛型类型static Type[]getGenericTypes(Type type) Gets the generic type arguments 获取泛型类型参数static Type[]getInterfaceGenericTypes(Class<?> clazz, Class<?> interfaceClass) Gets the generic type arguments of an interface 获取接口的泛型参数static TypegetMethodReturnGenericType(Method method) Gets the generic return type of a method 获取方法返回值的泛型类型static Class<?> getPrimitiveClass(Class<?> wrapperType) Gets the primitive class 获取原始类型static Class<?> getRawType(Type type) Gets the raw type of a generic type 获取泛型的原始类型static Type[]getSuperclassGenericTypes(Class<?> clazz) Gets the generic type arguments of the superclass 获取父类的泛型参数static Class<?> getWrapperClass(Class<?> primitiveType) Gets the wrapper class 获取包装类型static booleanChecks if the type is an array 检查是否为数组类型static booleanisAssignable(Class<?> superType, Class<?> subType) Checks if the type is assignable 检查类型是否可赋值static booleanisCollection(Class<?> clazz) Checks if the type is a collection 检查是否为集合类型static booleanisDateTime(Class<?> clazz) Checks if the type is a date/time type 检查是否为日期时间类型static boolean检查是否为 Map 类型static booleanChecks if the type is a number 检查是否为数字类型static booleanisPrimitive(Class<?> clazz) Checks if the type is a primitive 检查是否为原始类型static booleanisPrimitiveOrWrapper(Class<?> clazz) Checks if the type is a primitive or wrapper 检查是否为原始类型或包装类型static booleanChecks if the type is a String 检查是否为字符串类型static booleanChecks if the type is a wrapper 检查是否为包装类型
-
Method Details
-
isPrimitive
Checks if the type is a primitive 检查是否为原始类型 -
isWrapper
Checks if the type is a wrapper 检查是否为包装类型 -
isPrimitiveOrWrapper
Checks if the type is a primitive or wrapper 检查是否为原始类型或包装类型 -
isNumber
Checks if the type is a number 检查是否为数字类型 -
isCollection
Checks if the type is a collection 检查是否为集合类型 -
isMap
检查是否为 Map 类型 -
isArray
Checks if the type is an array 检查是否为数组类型 -
isString
Checks if the type is a String 检查是否为字符串类型 -
isDateTime
Checks if the type is a date/time type 检查是否为日期时间类型 -
getWrapperClass
-
getPrimitiveClass
-
getDefaultValue
Gets the default value for the type 获取类型的默认值 -
convert
-
convertOptional
-
getGenericTypes
-
getRawType
-
getFieldGenericType
-
getMethodReturnGenericType
-
getSuperclassGenericTypes
-
getInterfaceGenericTypes
-
isAssignable
-