public class Types extends Object
| 构造器和说明 |
|---|
Types() |
| 限定符和类型 | 方法和说明 |
|---|---|
static GenericArrayType |
arrayOf(Type componentType)
Returns an array type whose elements are all instances of
componentType. |
static Type |
checkPrimitiveArray(GenericArrayType genericArrayType) |
static boolean |
equal(Object a,
Object b) |
static boolean |
equals(Type a,
Type b)
Returns true if
a and b are equal. |
static Type |
getGenericSupertype(Type context,
Class<?> rawType,
Class<?> toResolve)
Returns the generic supertype for
supertype. |
static ParameterizedType |
getListParameterizedType(Type elementType)
List
|
static ParameterizedType |
getMapParameterizedType(Type keyType,
Type valueType)
Map
|
static ParameterizedType |
getParameterizedType(Type rawType) |
static ParameterizedType |
getParameterizedType(Type rawType,
Type... typeArguments) |
static ParameterizedType |
getParameterizedTypeWithOwnerType(Type ownerType,
Type rawType,
Type... typeArguments) |
static Class |
getPrimitiveWrapClass(Type type)
get the wrap class for a primitive type
|
static Class<?> |
getRawType(Type type) |
static ParameterizedType |
getSetParameterizedType(Type elementType)
List
|
static String |
getTypeSignature(String typeString)
get the type's signature in jvm runtime
|
static boolean |
isArray(Type type)
judge a type is a array or not
|
static boolean |
isClass(Type type)
judge a type is a class or not
|
static boolean |
isLiteralType(Type type)
判断是否为 字面量类型
|
static boolean |
isParameterizedType(Type type)
judge a type is a ParameterizedType
|
static boolean |
isPrimitive(Type type)
judge a type is a primitive type or not
|
static Type |
resolve(Type context,
Class<?> contextRawType,
Type toResolve) |
static WildcardType |
subtypeOf(Type bound)
Returns a type that represents an unknown type that extends
bound. |
static WildcardType |
supertypeOf(Type bound)
Returns a type that represents an unknown supertype of
bound. |
static Class<?> |
toClass(Type o)
convert any type to Class
|
static String |
typeToString(Type type)
show a type as a string, for examples:
|
public static boolean isPrimitive(Type type)
public static boolean isArray(Type type)
public static boolean isClass(Type type)
public static boolean isParameterizedType(Type type)
public static Class getPrimitiveWrapClass(Type type)
public static String getTypeSignature(@NonNull String typeString)
typeString - type FQNpublic static GenericArrayType arrayOf(Type componentType)
componentType.serializable generic array type.public static ParameterizedType getSetParameterizedType(Type elementType)
List
public static ParameterizedType getListParameterizedType(Type elementType)
List
public static ParameterizedType getMapParameterizedType(Type keyType, Type valueType)
Map
public static ParameterizedType getParameterizedType(Type rawType)
public static ParameterizedType getParameterizedType(Type rawType, Type... typeArguments)
public static ParameterizedType getParameterizedTypeWithOwnerType(Type ownerType, Type rawType, Type... typeArguments)
public static Type checkPrimitiveArray(GenericArrayType genericArrayType)
public static Type resolve(Type context, Class<?> contextRawType, Type toResolve)
context - contextRawType - toResolve - 将要被解析的类型public static Type getGenericSupertype(Type context, Class<?> rawType, Class<?> toResolve)
supertype. For example, given a class IntegerSet, the result for when supertype is Set.class is Set<Integer> and the
result when the supertype is Collection.class is Collection<Integer>.public static WildcardType subtypeOf(Type bound)
bound. For example, if
bound is CharSequence.class, this returns ? extends CharSequence. If
bound is Object.class, this returns ?, which is shorthand for ? extends Object.public static WildcardType supertypeOf(Type bound)
bound. For example, if bound is String.class, this returns ? super String.public static boolean isLiteralType(Type type)
Copyright © 2021. All rights reserved.