Here you can find the source of getGenericTypeClasses(List
public static List<Class<?>> getGenericTypeClasses(List<Class<?>> genericTypeClasses, Type... genericTypes)
//package com.java2s; //License from project: Apache License import java.lang.reflect.GenericArrayType; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.lang.reflect.WildcardType; import java.util.List; public class Main { public static List<Class<?>> getGenericTypeClasses(List<Class<?>> genericTypeClasses, Type... genericTypes) { for (Type genericType : genericTypes) { if (genericType instanceof ParameterizedType) { getGenericTypeClasses(genericTypeClasses, ((ParameterizedType) genericType).getActualTypeArguments()); } else if (genericType instanceof GenericArrayType) { getGenericTypeClasses(genericTypeClasses, ((GenericArrayType) genericType).getGenericComponentType()); } else if (genericType instanceof TypeVariable) { getGenericTypeClasses(genericTypeClasses, ((TypeVariable<?>) genericType).getBounds()); } else if (genericType instanceof WildcardType) { getGenericTypeClasses(genericTypeClasses, ((WildcardType) genericType).getUpperBounds()); getGenericTypeClasses(genericTypeClasses, ((WildcardType) genericType).getLowerBounds()); } else if (genericType instanceof Class) { Class<?> classType = (Class<?>) genericType; if (classType.isArray()) { getGenericTypeClasses(genericTypeClasses, classType.getComponentType()); } else { genericTypeClasses.add(classType); }// w w w . j ava 2 s . c o m } else { throw new IllegalStateException("unknown type:" + genericType); } } return genericTypeClasses; } }