// build a new TypeVariable -> Type map
Map<TypeVariable<?>, Type> map = new HashMap<TypeVariable<?>, Type>();
Class<?> clazz = targetClass;
while (!Object.class.equals(clazz)) {
Type genericSuperClass = clazz.getGenericSuperclass();
if (genericSuperClass instanceof ParameterizedType) {
collectActualTypeArguments((ParameterizedType) genericSuperClass, map);
}
collectActualTypeArguments(clazz.getGenericInterfaces(), map);
clazz = clazz.getSuperclass();