类 TypeUtils
java.lang.Object
com.alibaba.ageiport.common.utils.TypeUtils
Type的工具类封装
- 作者:
- lingyi
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static TypefindActualTypeArguments(Type type) 获取泛型的实际类型 如果泛型是 List这种, 继续找到D Type 可能是实际类型, 也可能是TypeVariableImpl static ParameterizedTypefindDirectTargetInterface(Class source, Class target) 获取直接继承目标接口, 此接口是泛型接口findParentTypeArgumentMap(Class source) static ParameterizedTypefindTargetInterfaceRecursive(Class source, Class target) flattenHierarchy(Class<?> concreteClass) static Class<?>获得Type对应的原始类getDeclaredFields(Class clazz) 获取所有的字段,包括父类getGenericParamType(Class source, Class target) static TypegetTypeArgument(Type type) 获得给定类的第一个泛型参数static TypegetTypeArgument(Type type, int index) 获得给定类的泛型参数static Type[]getTypeArguments(Type type) 获得指定类型中所有泛型参数类型,例如:static boolean是否未知类型
type为null或者TypeVariable都视为未知类型static ParameterizedTypetoParameterizedType(Type type)
-
构造器详细资料
-
TypeUtils
public TypeUtils()
-
-
方法详细资料
-
getGenericParamType
-
findDirectTargetInterface
获取直接继承目标接口, 此接口是泛型接口- 参数:
source-target-- 返回:
-
findTargetInterfaceRecursive
-
findActualTypeArguments
获取泛型的实际类型 如果泛型是 List
这种, 继续找到D Type 可能是实际类型, 也可能是TypeVariableImpl - 参数:
type-- 返回:
-
findActualTypeArgumentIfRawTypeIfList
-
findParentTypeArgumentMap
- 参数:
source-- 返回:
- {{"T", ParameterizedType}}
-
getDeclaredFields
获取所有的字段,包括父类- 参数:
clazz-- 返回:
-
flattenHierarchy
-
isUnknow
是否未知类型
type为null或者TypeVariable都视为未知类型- 参数:
type- Type类型- 返回:
- 是否未知类型
-
getTypeArgument
获得给定类的第一个泛型参数- 参数:
type- 被检查的类型,必须是已经确定泛型类型的类型- 返回:
Type,可能为null
-
getTypeArgument
获得给定类的泛型参数- 参数:
type- 被检查的类型,必须是已经确定泛型类型的类index- 泛型类型的索引号,即第几个泛型类型- 返回:
Type
-
getTypeArguments
获得指定类型中所有泛型参数类型,例如:class A<T> class B extends A<String>
通过此方法,传入B.class即可得到String
- 参数:
type- 指定类型- 返回:
- 所有泛型参数类型
-
getClass
获得Type对应的原始类- 参数:
type-Type- 返回:
- 原始类,如果无法获取原始类,返回
null
-
toParameterizedType
将Type转换为ParameterizedType
ParameterizedType用于获取当前类或父类中泛型参数化后的类型
一般用于获取泛型参数具体的参数类型,例如:class A<T> class B extends A<String>
通过此方法,传入B.class即可得到B
ParameterizedType,从而获取到String- 参数:
type-Type- 返回:
ParameterizedType
-