Support GenericArrayType in GenericTypeResolver method

Before this change GenericTypeResolver.resolveType supported
TypeVariable's and ParameterizedType's only. Now it also supports
GenericArrayType.
This commit is contained in:
Rossen Stoyanchev
2012-11-21 13:23:02 -05:00
parent 0e2904b71a
commit b36ab83ab3
2 changed files with 44 additions and 5 deletions

View File

@@ -371,8 +371,13 @@ public abstract class GenericTypeResolver {
* @return the type if it resolves to a Class, or <code>Object.class</code> otherwise
*/
public static Class<?> resolveType(Type genericType, Map<TypeVariable, Type> typeVariableMap) {
Type rawType = getRawType(genericType, typeVariableMap);
return (rawType instanceof Class ? (Class) rawType : Object.class);
Type resolvedType = getRawType(genericType, typeVariableMap);
if (resolvedType instanceof GenericArrayType) {
Type componentType = ((GenericArrayType) resolvedType).getGenericComponentType();
Class<?> componentClass = resolveType(componentType, typeVariableMap);
resolvedType = Array.newInstance(componentClass, 0).getClass();
}
return (resolvedType instanceof Class ? (Class) resolvedType : Object.class);
}
/**