public class GenericUtil extends Object
| 构造器和说明 |
|---|
GenericUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static GenericArrayType |
createGenericArrayType(Type componentType) |
static ParameterizedType |
createParameterizedType(Class<?> rawType,
Type ownerType,
Type... actualTypeArguments) |
static WildcardType |
createWildcardType(Type[] upperBounds,
Type[] lowerBounds) |
static Map<TypeVariable<?>,Type> |
getGenericReferenceMap(Class<?> clz) |
static Map<TypeVariable<?>,Type> |
getGenericReferenceMap(ParameterizedType parameterizedType) |
static Map<TypeVariable<?>,Type> |
getGenericReferenceMap(Type type) |
static Type[] |
getGenericTypes(Type sourceType,
Class<?> targetClass)
Get the actual generic types.
|
public static ParameterizedType createParameterizedType(Class<?> rawType, Type ownerType, Type... actualTypeArguments)
public static WildcardType createWildcardType(Type[] upperBounds, Type[] lowerBounds)
public static GenericArrayType createGenericArrayType(Type componentType)
public static Map<TypeVariable<?>,Type> getGenericReferenceMap(Type type)
public static Map<TypeVariable<?>,Type> getGenericReferenceMap(ParameterizedType parameterizedType)
public static Map<TypeVariable<?>,Type> getGenericReferenceMap(Class<?> clz)
public static Type[] getGenericTypes(Type sourceType, Class<?> targetClass)
class IntList extends ArrayList<Integer>{}
getGenericType(IntList.class, List.class);// {Integer.class}
getGenericType(IntList.class, Collection.class);// {Integer.class}
getGenericType(Integer.class, Comparable.class);// {Integer.class}
And nested situation
class A<E,T>{}
class B<E> extends A<E,Integer>{}
class C extends B<B<Boolean>>{}
class D<T> extends B<B<? extends T>>{}
class E extends D<Number>{}
getGenericType(B.class, A.class);// {E(TypeVariable), Integer.class}
getGenericType(C.class, A.class);// {B<Boolean>(ParameterizedType), Integer.class}
getGenericType(E.class, A.class);// {B<? extends Number>(ParameterizedType), Integer.class}
sourceType - The type to find generic type. May Class or ParameterizedTypetargetClass - Find the actual generic type on this type.Class, TypeVariable, ParameterizedType.Copyright © 2018. All rights reserved.