Here you can find the source of getGenericTypeClass(Class> clazz, int index)
public static Class<?> getGenericTypeClass(Class<?> clazz, int index)
//package com.java2s; //License from project: Apache License import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { public static Class<?> getGenericTypeClass(Class<?> clazz, int index) { Class<?> superClass = clazz.getSuperclass(); Type genericSuperClass = clazz.getGenericSuperclass(); while (!(genericSuperClass instanceof ParameterizedType)) { genericSuperClass = superClass.getGenericSuperclass(); superClass = superClass.getSuperclass(); }/*from w w w . jav a 2 s .co m*/ Type[] types = ((ParameterizedType) genericSuperClass).getActualTypeArguments(); if (index < types.length) { return (Class<?>) types[index]; } else { return null; } } }