| Constructor and Description |
|---|
TypeKit() |
| Modifier and Type | Method and Description |
|---|---|
static Type |
getActualType(Type actualType,
Class<?> typeDefineClass,
Type typeVariable)
获取指定泛型变量对应的真实类型
由于子类中泛型参数实现和父类(接口)中泛型定义位置是一一对应的,因此可以通过对应关系找到泛型实现类型
使用此方法注意:
|
static Type |
getActualType(Type type,
Field field)
获得泛型字段对应的泛型实际类型,如果此变量没有对应的实际类型,返回null
|
static Type |
getActualType(Type type,
ParameterizedType parameterizedType)
获得泛型变量对应的泛型实际类型,如果此变量没有对应的实际类型,返回null
此方法可以处理复杂的泛型化对象,类似于Map<User, Key<Long>>
|
static Type |
getActualType(Type type,
Type typeVariable)
获得泛型变量对应的泛型实际类型,如果此变量没有对应的实际类型,返回null
此方法可以处理:
|
static Type[] |
getActualTypes(Type actualType,
Class<?> typeDefineClass,
Type... typeVariables)
获取指定泛型变量对应的真实类型
由于子类中泛型参数实现和父类(接口)中泛型定义位置是一一对应的,因此可以通过对应关系找到泛型实现类型
使用此方法注意:
|
static Type[] |
getActualTypes(Type type,
Type... typeVariables)
获得泛型变量对应的泛型实际类型,如果此变量没有对应的实际类型,返回null
|
static Class<?> |
getClass(Field field)
获得Field对应的原始类
|
static Class<?> |
getClass(Type type)
获得Type对应的原始类
|
static Type |
getClosestParentType(Class<?> cls,
Class<?> superClass)
获取与
superClass 指定的超类最接近的父类 |
static Type |
getFieldType(Class<?> clazz,
String fieldName)
获得字段的泛型类型
|
static Class<?> |
getFirstParamClass(Method method)
获取方法的第一个参数类
|
static Type |
getFirstParamType(Method method)
获取方法的第一个参数类型
优先获取方法的GenericParameterTypes,如果获取不到,则获取ParameterTypes
|
static Type[] |
getImplicitBounds(TypeVariable<?> typeVariable)
如果
TypeVariable.getBounds()返回一个空数组,
则返回一个包含Object 唯一类型的数组. |
static Type[] |
getImplicitLowerBounds(WildcardType wildcardType)
|
static Type[] |
getImplicitUpperBounds(WildcardType wildcardType)
如果
WildcardType.getUpperBounds()返回一个空数组,
则返回一个包含Object唯一值的数组否则,
它将返回传递给normalizeUpperBounds(java.lang.reflect.Type[])的
WildcardType.getUpperBounds()的结果 |
static Class<?> |
getParamClass(Method method,
int index)
获取方法的参数类
|
static Class<?>[] |
getParamClasses(Method method)
解析方法的参数类型列表
依赖jre\lib\rt.jar
|
static Type |
getParamType(Method method,
int index)
获取方法的参数类型
优先获取方法的GenericParameterTypes,如果获取不到,则获取ParameterTypes
|
static Type[] |
getParamTypes(Method method)
获取方法的参数类型列表
优先获取方法的GenericParameterTypes,如果获取不到,则获取ParameterTypes
|
static Class<?> |
getRawType(Type type,
Type assigningType)
根据上下文获取Java类型的原始类型
主要用于
TypeVariables和GenericArrayType |
static Class<?> |
getReturnClass(Method method)
解析方法的返回类型类列表
|
static Type |
getReturnType(Method method)
获取方法的返回值类型
获取方法的GenericReturnType
|
static Type |
getType(Field field)
获取字段对应的Type类型
方法优先获取GenericType,获取不到则获取Type
|
static Type |
getTypeArgument(Type type)
获得给定类的第一个泛型参数
|
static Type |
getTypeArgument(Type type,
int index)
获得给定类的泛型参数
|
static Map<TypeVariable<?>,Type> |
getTypeArguments(Class<?> cls,
Class<?> toClass,
Map<TypeVariable<?>,Type> subtypeVarAssigns)
在
toClass的上下文中返回类的类型参数的映射 |
static Map<TypeVariable<?>,Type> |
getTypeArguments(ParameterizedType type)
检索此参数化类型的所有类型参数,包括所有者层次结构参数
|
static Map<TypeVariable<?>,Type> |
getTypeArguments(ParameterizedType parameterizedType,
Class<?> toClass,
Map<TypeVariable<?>,Type> subtypeVarAssigns)
在
toClass的上下文中返回参数化类型的类型参数的映射 |
static Type[] |
getTypeArguments(Type type)
获得指定类型中所有泛型参数类型,例如:
|
static Map<TypeVariable<?>,Type> |
getTypeArguments(Type type,
Class<?> toClass)
获取基于子类型的类/接口的类型参数
|
static Map<TypeVariable<?>,Type> |
getTypeArguments(Type type,
Class<?> toClass,
Map<TypeVariable<?>,Type> subtypeVarAssigns)
在
toClass的上下文中返回type的类型参数的映射 |
static Map<Type,Type> |
getTypeMap(Class<?> clazz)
获取泛型变量和泛型实际类型的对应关系Map
|
static boolean |
hasTypeVariable(Type... types)
指定泛型数组中是否含有泛型变量
|
static boolean |
isAbstract(Class<?> clazz)
是否为抽象类
|
static boolean |
isAbstractOrInterface(Class<?> clazz)
是抽象类或者接口
|
static boolean |
isArray(Class<?> clazz)
是否为 数组 class 类型
|
static boolean |
isArrayType(Type type)
了解指定的类型是否表示数组类型
|
static boolean |
isAssignable(Type type,
Type toType)
检查subject类型是否可以按照Java泛型规则隐式转换为目标类型.
|
static boolean |
isBase(Class<?> clazz)
是否为基本类型
1.
|
static boolean |
isCollection(Class<?> clazz)
是否为 Collection class 类型
|
static boolean |
isIterable(Class<?> clazz)
是否为 Iterable class 类型
|
static boolean |
isJavaBean(Class<?> clazz)
是否为标准的类
这个类必须:
|
static boolean |
isJdk(Class<?> clazz)
判断一个类是JDK 自带的类型
jdk 自带的类,classLoader 是为空的
|
static boolean |
isMap(Class<?> clazz)
是否为 map class 类型
|
static boolean |
isUnknown(Type type)
是否未知类型
type为null或者
TypeVariable 都视为未知类型 |
static Type[] |
normalizeUpperBounds(Type[] bounds)
该方法在类型变量类型和通配符类型中去除冗余的上界类型
|
static ParameterizedType |
toParameterizedType(Type type)
|
public static boolean isMap(Class<?> clazz)
clazz - 对象类型public static boolean isArray(Class<?> clazz)
clazz - 对象类型public static boolean isCollection(Class<?> clazz)
clazz - 对象类型public static boolean isIterable(Class<?> clazz)
clazz - 对象类型public static boolean isBase(Class<?> clazz)
clazz - 对象类型public static boolean isAbstract(Class<?> clazz)
clazz - 类public static boolean isAbstractOrInterface(Class<?> clazz)
clazz - 类信息public static boolean isJavaBean(Class<?> clazz)
0、不为 null 1、非接口 2、非抽象类 3、非Enum枚举 4、非数组 5、非注解 6、非原始类型(int, long等) 7、非集合 Iterable 8、非 Map.clas 9、非 JVM 生成类
clazz - 类public static boolean isJdk(Class<?> clazz)
clazz - 类public static boolean isAssignable(Type type, Type toType)
Class对象,
则该方法返回ClassKit.isAssignable(Class, Class)的结果type - 要分配给目标类型的主题类型toType - 目标类型type可赋值给toType,则true.public static boolean isArrayType(Type type)
type - 要检查的类型type是数组类或GenericArrayType,则为truepublic static boolean isUnknown(Type type)
TypeVariable 都视为未知类型type - Type类型public static Class<?> getClass(Type type)
type - Typenullpublic static Class<?> getClass(Field field)
field - Fieldnullpublic static Type getType(Field field)
field - 字段Type,可能为nullpublic static Type getFieldType(Class<?> clazz, String fieldName)
clazz - Bean类fieldName - 字段名public static Type getFirstParamType(Method method)
method - 方法Type,可能为nullpublic static Class<?> getFirstParamClass(Method method)
method - 方法nullpublic static Type getParamType(Method method, int index)
method - 方法index - 第几个参数的索引,从0开始计数Type,可能为nullpublic static Class<?> getParamClass(Method method, int index)
method - 方法index - 第几个参数的索引,从0开始计数nullpublic static Type[] getParamTypes(Method method)
method - 方法Type列表,可能为nullMethod.getGenericParameterTypes(),
Method.getParameterTypes()public static Class<?>[] getParamClasses(Method method)
method - t方法Method.getGenericParameterTypes(),
Method.getParameterTypes()public static Type getReturnType(Method method)
method - 方法Type,可能为nullMethod.getGenericReturnType(),
Method.getReturnType()public static Class<?> getReturnClass(Method method)
method - 方法Method.getGenericReturnType(),
Method.getReturnType()public static Type getTypeArgument(Type type)
type - 被检查的类型,必须是已经确定泛型类型的类型Type,可能为nullpublic static Type getTypeArgument(Type type, int index)
type - 被检查的类型,必须是已经确定泛型类型的类index - 泛型类型的索引号,既第几个泛型类型Typepublic static Type[] getTypeArguments(Type type)
class A<T> class B extends A<String>
通过此方法,传入B.class即可得到String
type - 指定类型public static Map<TypeVariable<?>,Type> getTypeArguments(ParameterizedType type)
type - 指定要从中获取参数的主题参数化类型Map.public static Map<TypeVariable<?>,Type> getTypeArguments(Type type, Class<?> toClass)
type - 用于确定toClass的类型参数的类型toClass - 类型参数将根据子类型type确定的类Mappublic static Map<TypeVariable<?>,Type> getTypeArguments(Type type, Class<?> toClass, Map<TypeVariable<?>,Type> subtypeVarAssigns)
toClass的上下文中返回type的类型参数的映射type - 问题类型toClass - 类subtypeVarAssigns - 带有类型变量的映射Mappublic static Map<TypeVariable<?>,Type> getTypeArguments(Class<?> cls, Class<?> toClass, Map<TypeVariable<?>,Type> subtypeVarAssigns)
toClass的上下文中返回类的类型参数的映射cls - 要确定类型参数的类toClass - 上下文类subtypeVarAssigns - 带有类型变量的映射Mappublic static Map<TypeVariable<?>,Type> getTypeArguments(ParameterizedType parameterizedType, Class<?> toClass, Map<TypeVariable<?>,Type> subtypeVarAssigns)
toClass的上下文中返回参数化类型的类型参数的映射parameterizedType - 参数化类型toClass - 类subtypeVarAssigns - 带有类型变量的映射Mappublic static Type getClosestParentType(Class<?> cls, Class<?> superClass)
superClass 指定的超类最接近的父类cls - 类superClass - 超类public static Type[] getActualTypes(Type actualType, Class<?> typeDefineClass, Type... typeVariables)
1. superClass必须是clazz的父类或者clazz实现的接口 2. typeVariable必须在superClass中声明
actualType - 真实类型所在类,此类中记录了泛型参数对应的实际类型typeDefineClass - 泛型变量声明所在类或接口,此类中定义了泛型类型typeVariables - 泛型变量,需要的实际类型对应的泛型参数public static Type getActualType(Type actualType, Class<?> typeDefineClass, Type typeVariable)
1. superClass必须是clazz的父类或者clazz实现的接口 2. typeVariable必须在superClass中声明
actualType - 真实类型所在类,此类中记录了泛型参数对应的实际类型typeDefineClass - 泛型变量声明所在类或接口,此类中定义了泛型类型typeVariable - 泛型变量,需要的实际类型对应的泛型参数public static ParameterizedType toParameterizedType(Type type)
Type 转换为ParameterizedType
ParameterizedType用于获取当前类或父类中泛型参数化后的类型
一般用于获取泛型参数具体的参数类型,例如:
class A<T> class B extends A<String>
通过此方法,传入B.class即可得到BParameterizedType,从而获取到String
type - TypeParameterizedTypepublic static Map<Type,Type> getTypeMap(Class<?> clazz)
T org.aoju.core.Version
E java.lang.Integer
clazz - 被解析的包含泛型参数的类public static Type getActualType(Type type, Field field)
type - 实际类型明确的类field - 字段public static Type getActualType(Type type, Type typeVariable)
1. 泛型化对象,类似于Map<User, Key<Long>>
2. 泛型变量,类似于T
type - 类typeVariable - 泛型变量,例如T等public static Type getActualType(Type type, ParameterizedType parameterizedType)
type - 类parameterizedType - 泛型变量,例如List<T>等public static Type[] getActualTypes(Type type, Type... typeVariables)
type - 类typeVariables - 泛型变量数组,例如T等public static Class<?> getRawType(Type type, Type assigningType)
TypeVariables和GenericArrayTypetype - 类型assigningType - 要解析的类型Class对象或nullpublic static Type[] getImplicitBounds(TypeVariable<?> typeVariable)
TypeVariable.getBounds()返回一个空数组,
则返回一个包含Object 唯一类型的数组.
否则返回TypeVariable.getBounds()
传递给normalizeUpperBounds(java.lang.reflect.Type[])的结果typeVariable - 类型变量public static Type[] getImplicitUpperBounds(WildcardType wildcardType)
WildcardType.getUpperBounds()返回一个空数组,
则返回一个包含Object唯一值的数组否则,
它将返回传递给normalizeUpperBounds(java.lang.reflect.Type[])的
WildcardType.getUpperBounds()的结果wildcardType - 通配符类型public static Type[] getImplicitLowerBounds(WildcardType wildcardType)
wildcardType - 通配符类型public static Type[] normalizeUpperBounds(Type[] bounds)
bounds - 表示WildcardType或
TypeVariable的上界的类型数组.bounds的值减去冗余类型的数组.public static boolean hasTypeVariable(Type... types)
types - 泛型数组Copyright © 2022. All rights reserved.