package org.springframework.core;
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.
Cache from Class to TypeVariable Map
Determine the target type for the given parameter specification.
- Parameters:
methodParam the method parameter specification- Returns:
- the corresponding generic parameter type
Assert.notNull(methodParam, "MethodParameter must not be null");
Determine the target type for the given generic parameter type.
- Parameters:
methodParam the method parameter specificationclazz the class to resolve type variables against- Returns:
- the corresponding generic parameter or return type
Assert.notNull(clazz, "Class must not be null");
methodParam.typeVariableMap = typeVariableMap;
Determine the target type for the generic return type of the given method.
- Parameters:
method the method to introspectclazz the class to resolve type variables against- Returns:
- the corresponding generic parameter or return type
Assert.notNull(method, "Method must not be null");
Assert.notNull(clazz, "Class must not be null");
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.
- Parameters:
clazz the target class to check againstgenericIfc the generic interface to resolve the type argument from- Returns:
- the resolved type of the argument, or
null if not resolvable
if (typeArgs.length != 1) { genericIfc.getName() + "] but found " + typeArgs.length);
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.
- Parameters:
clazz the target class to check againstgenericIfc the generic interface 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
while (classToIntrospect != null) { if (genericIfc.equals(rawType)) { for (int i = 0; i < typeArgs.length; i++) { Extract a class instance from given Type.
Resolve the specified generic type against the given TypeVariable map.
- Parameters:
genericType the generic type to resolvetypeVariableMap the TypeVariable Map to resolved against- Returns:
- the type if it resolves to a Class, or
Object.class otherwise
Determine the raw type for the given generic parameter type.
- Parameters:
genericType the generic type to resolvetypeVariableMap the TypeVariable Map to resolved against- Returns:
- the resolved raw type
Type resolvedType = genericType;
resolvedType = typeVariableMap.get(tv);
if (resolvedType == null) { Build a mapping of
TypeVariable names to concrete
java.lang.Class for the specified
java.lang.Class. Searches all super types,
enclosing types and interfaces.
if (typeVariableMap == null) { if (bounds.length == 0) { for (Type genericInterface : genericInterfaces) { else if (genericInterface instanceof Class) { Read the
TypeVariables from the supplied
java.lang.reflect.ParameterizedType
and add mappings corresponding to the
TypeVariable name ->
concrete type to the supplied
java.util.Map.
Consider this case:
public interface Foo {
..
}
public class FooImpl implements Foo<String, Integer> {
..
}
For '
FooImpl' the following mappings would be added to the
java.util.Map:
{S=java.lang.String, T=java.lang.Integer}.
for (int i = 0; i < actualTypeArguments.length; i++) { Type actualTypeArgument = actualTypeArguments[i];
if (actualTypeArgument instanceof Class) { typeVariableMap.put(variable, actualTypeArgument);
typeVariableMap.put(variable, actualTypeArgument);
typeVariableMap.put(variable, actualTypeArgument);
Type resolvedType = typeVariableMap.get(typeVariableArgument);
if (resolvedType == null) { typeVariableMap.put(variable, resolvedType);