类 GenericTypeResolver
- java.lang.Object
- org.springframework.core.GenericTypeResolver
public abstract class GenericTypeResolver extends Object
Helper class for resolving generic types against type variables.Mainly intended for usage within the framework, resolving method parameter types even when they are declared generically.
- 从以下版本开始:
- 2.5.2
- 作者:
- Juergen Hoeller, Rob Harrop, Sam Brannen, Phillip Webb
构造器概要
构造器 构造器 说明 GenericTypeResolver()
方法概要
所有方法 静态方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static Type
getTargetType(MethodParameter methodParameter)
已过时。as of Spring 4.0, useMethodParameter.getGenericParameterType()
static Map<TypeVariable,Type>
getTypeVariableMap(Class<?> clazz)
static Class<?>
resolveParameterType(MethodParameter methodParameter, Class<?> implementationClass)
Determine the target type for the given generic parameter type.static Class<?>
resolveReturnType(Method method, Class<?> clazz)
Determine the target type for the generic return type of the given method, where formal type variables are declared on the given class.static Class<?>
resolveReturnTypeArgument(Method method, Class<?> genericIfc)
Resolve the single type argument of the given generic interface against the given target method which is assumed to return the given interface or an implementation of it.static Class<?>
resolveReturnTypeForGenericMethod(Method method, Object[] args, ClassLoader classLoader)
已过时。as of Spring Framework 4.3.8, superseded byResolvableType
usagestatic Class<?>
resolveType(Type genericType, Map<TypeVariable,Type> map)
Resolve the specified generic type against the given TypeVariable map.static Class<?>
resolveTypeArgument(Class<?> clazz, Class<?> genericIfc)
Resolve the single type argument of the given generic interface against the given target class which is assumed to implement the generic interface and possibly declare a concrete type for its type variable.static Class<?>[]
resolveTypeArguments(Class<?> clazz, Class<?> genericIfc)
Resolve the type arguments of the given generic interface against the given target class which is assumed to implement the generic interface and possibly declare concrete types for its type variables.
构造器详细资料
GenericTypeResolver
public GenericTypeResolver()
方法详细资料
getTargetType
@Deprecated public static Type getTargetType(MethodParameter methodParameter)
已过时。as of Spring 4.0, useMethodParameter.getGenericParameterType()
Determine the target type for the given parameter specification.- 参数:
methodParameter
- the method parameter specification- 返回:
- the corresponding generic parameter type
resolveParameterType
public static Class<?> resolveParameterType(MethodParameter methodParameter, Class<?> implementationClass)
Determine the target type for the given generic parameter type.- 参数:
methodParameter
- the method parameter specificationimplementationClass
- the class to resolve type variables against- 返回:
- the corresponding generic parameter or return type
resolveReturnType
public static Class<?> resolveReturnType(Method method, Class<?> clazz)
Determine the target type for the generic return type of the given method, where formal type variables are declared on the given class.- 参数:
method
- the method to introspectclazz
- the class to resolve type variables against- 返回:
- the corresponding generic parameter or return type
resolveReturnTypeForGenericMethod
@Deprecated public static Class<?> resolveReturnTypeForGenericMethod(Method method, Object[] args, ClassLoader classLoader)
已过时。as of Spring Framework 4.3.8, superseded byResolvableType
usageDetermine the target type for the generic return type of the given generic method, where formal type variables are declared on the given method itself.For example, given a factory method with the following signature, if
resolveReturnTypeForGenericMethod()
is invoked with the reflected method forcreatProxy()
and anObject[]
array containingMyService.class
,resolveReturnTypeForGenericMethod()
will infer that the target return type isMyService
.public static <T> T createProxy(Class<T> clazz)
Possible Return Values
- the target return type, if it can be inferred
- the standard return type, if the given
method
does not declare any formal type variables - the standard return type, if the target return type cannot be inferred (e.g., due to type erasure)
null
, if the length of the given arguments array is shorter than the length of the formal argument list for the given method
- 参数:
method
- the method to introspect, nevernull
args
- the arguments that will be supplied to the method when it is invoked (nevernull
)classLoader
- the ClassLoader to resolve class names against, if necessary (may benull
)- 返回:
- the resolved target return type, the standard return type, or
null
- 从以下版本开始:
- 3.2.5
resolveReturnTypeArgument
public static Class<?> resolveReturnTypeArgument(Method method, Class<?> genericIfc)
Resolve the single type argument of the given generic interface against the given target method which is assumed to return the given interface or an implementation of it.- 参数:
method
- the target method to check the return type ofgenericIfc
- the generic interface or superclass to resolve the type argument from- 返回:
- the resolved parameter type of the method return type, or
null
if not resolvable or if the single argument is of typeWildcardType
.
resolveTypeArgument
public static Class<?> resolveTypeArgument(Class<?> clazz, Class<?> genericIfc)
Resolve the single type argument of the given generic interface against the given target class which is assumed to implement the generic interface and possibly declare a concrete type for its type variable.- 参数:
clazz
- the target class to check againstgenericIfc
- the generic interface or superclass to resolve the type argument from- 返回:
- the resolved type of the argument, or
null
if not resolvable
resolveTypeArguments
public static Class<?>[] resolveTypeArguments(Class<?> clazz, Class<?> genericIfc)
Resolve the type arguments of the given generic interface against the given target class which is assumed to implement the generic interface and possibly declare concrete types for its type variables.- 参数:
clazz
- the target class to check againstgenericIfc
- the generic interface or superclass to resolve the type argument from- 返回:
- the resolved type of each argument, with the array size matching the number of actual type arguments, or
null
if not resolvable
resolveType
public static Class<?> resolveType(Type genericType, Map<TypeVariable,Type> map)
Resolve the specified generic type against the given TypeVariable map.Used by Spring Data.
- 参数:
genericType
- the generic type to resolvemap
- the TypeVariable Map to resolved against- 返回:
- the type if it resolves to a Class, or
Object.class
otherwise
getTypeVariableMap
public static Map<TypeVariable,Type> getTypeVariableMap(Class<?> clazz)
Build a mapping ofTypeVariable names
toconcrete classes
for the specifiedClass
. Searches all super types, enclosing types and interfaces.