- java.lang.Object
-
- org.redkale.util.TypeToken<T>
-
- 类型参数:
T- 泛型
public abstract class TypeToken<T> extends Object
获取泛型的Type类详情见: https://redkale.org
- 作者:
- zhangjx
-
-
构造器概要
构造器 构造器 说明 TypeToken()
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static booleancontainsUnknownType(Type type)判断泛型知否包含了不确定的数据类型static TypecreateClassType(Type type, Type declaringType0)动态创建类型为ParameterizedType或Class的Typestatic TypecreateParameterizedType(Type ownerType0, Type rawType0, Type... actualTypeArguments0)动态创建 ParameterizedType
例如: List<String>: createParameterizedType(null, List.class, String.class)static Type[]getGenericType(Type[] types, Type declaringClass)将泛型中不确定的类型转成确定性类型static TypegetGenericType(Type paramType, Type declaringClass)获取TypeVariable对应的实际Type, 如果type不是TypeVariable 直接返回type。TypegetType()具体泛型类型static booleanisClassType(Type type)判断Type是否能确定最终的class, 是则返回true,存在通配符或者不确定类型则返回false。static ClassprimitiveToWrapper(Class clazz)获取primitive类对应的box类型static ClasstypeToClass(Type type)获取type的主类static ClasstypeToClassOrElse(Type type, Class defClass)获取type的主类,如果是不确定类型,则返回defClass
-
-
-
方法详细资料
-
getType
public final Type getType()
具体泛型类型- 返回:
- 泛型
-
isClassType
public static final boolean isClassType(Type type)
判断Type是否能确定最终的class, 是则返回true,存在通配符或者不确定类型则返回false。 例如: Map< String, String > 返回 ture; Map< ? extends Serializable, String > 返回false;- 参数:
type- Type对象- 返回:
- 是否可反解析
-
containsUnknownType
public static final boolean containsUnknownType(Type type)
判断泛型知否包含了不确定的数据类型- 参数:
type- 类型- 返回:
- 是否含不确定类型
-
typeToClassOrElse
public static final Class typeToClassOrElse(Type type, Class defClass)
获取type的主类,如果是不确定类型,则返回defClass- 参数:
type- 类型defClass- 默认类- 返回:
- 确定的类型
-
getGenericType
public static Type[] getGenericType(Type[] types, Type declaringClass)
将泛型中不确定的类型转成确定性类型- 参数:
types- 泛型集合declaringClass- 宿主类型- 返回:
- 确定性类型集合
-
primitiveToWrapper
public static Class primitiveToWrapper(Class clazz)
获取primitive类对应的box类型- 参数:
clazz- primitive类- 返回:
- 基础类型box类型
-
getGenericType
public static Type getGenericType(Type paramType, Type declaringClass)
获取TypeVariable对应的实际Type, 如果type不是TypeVariable 直接返回type。public abstract class Key { } public abstract class Val { } public abstract class AService <K extends Key, V extends Val> { public abstract V findValue(K key); public abstract Sheet<V> queryValue(K key); } public class Key2 extends Key { } public class Val2 extends Val { } public class Service2 extends Service <Key2, Val2> { public Val2 findValue(Key2 key){ return new Val2(); } public Sheet<Val2> queryValue(Key2 key){ return new Sheet(); } }- 参数:
paramType- 泛型declaringClass- 泛型依附类- 返回:
- Type
-
createClassType
public static Type createClassType(Type type, Type declaringType0)
动态创建类型为ParameterizedType或Class的Type- 参数:
type- 当前泛型declaringType0- 子类- 返回:
- Type
-
createParameterizedType
public static Type createParameterizedType(Type ownerType0, Type rawType0, Type... actualTypeArguments0)
动态创建 ParameterizedType
例如: List<String>: createParameterizedType(null, List.class, String.class)- 参数:
ownerType0- ParameterizedType 的 ownerType, 一般为nullrawType0- ParameterizedType 的 rawTypeactualTypeArguments0- ParameterizedType 的 actualTypeArguments- 返回:
- Type
-
-