/** * Get the underlying class for a type, or null if the type is a variable type. * * @param type the type * @return the underlying class */ private static Class<?> getClass(Type type) { if (type instanceof Class) { return (Class) type; } else if (type instanceof ParameterizedType) { return getClass(((ParameterizedType) type).getRawType()); } else if (type instanceof GenericArrayType) { Type componentType = ((GenericArrayType) type).getGenericComponentType(); Class<?> componentClass = getClass(componentType); if (componentClass != null) { return Array.newInstance(componentClass, 0).getClass(); } else { return null; } } else { return null; } }
Map<Type, Type> resolvedTypes = new HashMap<>(); Type type = childClass; Class typeClass = getClass(type); typeClass = getClass(type); if (typeClass == null) { throw new IllegalArgumentException("Unable to find the class for the type " + type); baseType = resolvedTypes.get(baseType); typeArgumentsAsClasses.add(getClass(baseType));