public class GenericTypeReflector extends Object
| Constructor and Description |
|---|
GenericTypeReflector() |
| Modifier and Type | Method and Description |
|---|---|
static Type |
addWildcardParameters(Class<?> clazz)
Returns a type representing the class, with all type parameters the unbound wildcard ("?").
|
static ParameterizedType |
capture(ParameterizedType type)
Applies capture conversion to the given type.
|
static Type |
capture(Type type)
Applies capture conversion to the given type.
|
static Class<?> |
erase(Type type)
Returns the erasure of the given type.
|
static Type |
getArrayComponentType(Type type)
If type is an array type, returns the type of the component of the array.
|
static Type |
getExactFieldType(Field f,
Type type)
Returns the exact type of the given field in the given type.
|
static Type[] |
getExactParameterTypes(Method m,
Type type)
Returns the exact parameter types of the given method in the given type.
|
static Type |
getExactReturnType(Method m,
Type type)
Returns the exact return type of the given method in the given type.
|
static Type |
getExactSuperType(Type type,
Class<?> searchClass)
Finds the most specific supertype of type whose erasure is searchClass.
|
static String |
getTypeName(Type type)
Returns the display name of a Type.
|
static Type |
getTypeParameter(Type type,
TypeVariable<? extends Class<?>> variable)
Gets the type parameter for a given type that is the value for a given type variable.
|
static List<Class<?>> |
getUpperBoundClassAndInterfaces(Type type)
Returns list of classes and interfaces that are supertypes of the given type.
|
static boolean |
isSuperType(Type superType,
Type subType)
Checks if the capture of subType is a subtype of superType
|
public static Type addWildcardParameters(Class<?> clazz)
public static Type getExactSuperType(Type type, Class<?> searchClass)
ParameterizedType if searchClass is a real class or interface and type has parameters for itGenericArrayType if searchClass is an array type, and type has type parameters for itClass if type is a raw type, or has no type parameters for searchClassFor example, with class StringList implements List<String>, getExactSuperType(StringList.class, Collection.class)
returns a ParameterizedType representing Collection<String>.
public static Type getTypeParameter(Type type, TypeVariable<? extends Class<?>> variable)
type - The type to inspect.variable - The type variable to find the value for.public static boolean isSuperType(Type superType, Type subType)
public static Type getArrayComponentType(Type type)
public static Type getExactReturnType(Method m, Type type)
public static Type getExactFieldType(Field f, Type type)
public static Type[] getExactParameterTypes(Method m, Type type)
public static ParameterizedType capture(ParameterizedType type)
capture(Type)public static List<Class<?>> getUpperBoundClassAndInterfaces(Type type)
This is mostly useful if you get a type from one of the other methods in GenericTypeReflector, but you don't want to deal with all the different sorts of types, and you are only really interested in concrete classes and interfaces.
Copyright © 2008–2017. All rights reserved.