Package org.springframework.core
Class GenericTypeResolver
java.lang.Object
org.springframework.core.GenericTypeResolver
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.
- Since:
- 2.5.2
- Author:
- Juergen Hoeller, Rob Harrop, Sam Brannen, Phillip Webb
-
Method Summary
Modifier and TypeMethodDescriptionstatic Map<TypeVariable,
Type> getTypeVariableMap
(Class<?> clazz) static Class<?>
resolveParameterType
(MethodParameter methodParameter, Class<?> implementationClass) Deprecated.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<?> genericType) Resolve the single type argument of the given generic type against the given target method which is assumed to return the given type or an implementation of it.static Type
resolveType
(Type genericType, Class<?> contextClass) Resolve the given generic type against the given context class, substituting type variables as far as possible.static Class<?>
resolveType
(Type genericType, Map<TypeVariable, Type> map) Resolve the specified generic type against the given TypeVariable map.static Class<?>
resolveTypeArgument
(Class<?> clazz, Class<?> genericType) Resolve the single type argument of the given generic type against the given target class which is assumed to implement the given type and possibly declare a concrete type for its type variable.static Class<?>[]
resolveTypeArguments
(Class<?> clazz, Class<?> genericType) Resolve the type arguments of the given generic type against the given target class which is assumed to implement or extend from the given type and possibly declare concrete types for its type variables.
-
Method Details
-
resolveParameterType
@Deprecated public static Class<?> resolveParameterType(MethodParameter methodParameter, Class<?> implementationClass) Deprecated.since 5.2 in favor ofmethodParameter.withContainingClass(implementationClass).getParameterType()
Determine the target type for the given generic parameter type.- Parameters:
methodParameter
- the method parameter specificationimplementationClass
- the class to resolve type variables against- Returns:
- the corresponding generic parameter or return type
-
resolveReturnType
Determine the target type for the generic return type of the given method, where formal type variables are declared on the given class.- Parameters:
method
- the method to introspectclazz
- the class to resolve type variables against- Returns:
- the corresponding generic parameter or return type
-
resolveReturnTypeArgument
Resolve the single type argument of the given generic type against the given target method which is assumed to return the given type or an implementation of it.- Parameters:
method
- the target method to check the return type ofgenericType
- the generic interface or superclass to resolve the type argument from- Returns:
- the resolved parameter type of the method return type, or
null
if not resolvable or if the single argument is of typeWildcardType
.
-
resolveTypeArgument
Resolve the single type argument of the given generic type against the given target class which is assumed to implement the given type and possibly declare a concrete type for its type variable.- Parameters:
clazz
- the target class to check againstgenericType
- the generic interface or superclass to resolve the type argument from- Returns:
- the resolved type of the argument, or
null
if not resolvable
-
resolveTypeArguments
Resolve the type arguments of the given generic type against the given target class which is assumed to implement or extend from the given type and possibly declare concrete types for its type variables.- Parameters:
clazz
- the target class to check againstgenericType
- the generic interface or superclass to resolve the type argument from- Returns:
- the resolved type of each argument, with the array size matching the
number of actual type arguments, or
null
if not resolvable
-
resolveType
Resolve the given generic type against the given context class, substituting type variables as far as possible.- Parameters:
genericType
- the (potentially) generic typecontextClass
- a context class for the target type, for example a class in which the target type appears in a method signature (can benull
)- Returns:
- the resolved type (possibly the given generic type as-is)
- Since:
- 5.0
-
resolveType
Resolve the specified generic type against the given TypeVariable map.Used by Spring Data.
- Parameters:
genericType
- the generic type to resolvemap
- the TypeVariable Map to resolved against- Returns:
- the type if it resolves to a Class, or
Object.class
otherwise
-
getTypeVariableMap
Build a mapping ofTypeVariable names
toconcrete classes
for the specifiedClass
. Searches all supertypes, enclosing types and interfaces.- See Also:
-
methodParameter.withContainingClass(implementationClass).getParameterType()