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.
Only usable on Java 5. Use an appropriate JdkVersion check before
calling this class, if a fallback for JDK 1.4 is desirable.
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 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 = (Type) 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.
Map typeVariableMap = (Map) (ref != null ? ref.get() : null);
if (typeVariableMap == null) { if (bounds.length == 0) { for (int i = 0; i < genericInterfaces.length; i++) { Type genericInterface = genericInterfaces[i];
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 = (Type) typeVariableMap.get(typeVariableArgument);
if (resolvedType == null) { typeVariableMap.put(variable, resolvedType);