Here you can find the source of getGenericParameter(Class clazz, int index)
public static <T> Class<T> getGenericParameter(Class clazz, int index)
//package com.java2s; //License from project: Mozilla Public License import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { public static <T> Class<T> getGenericParameter(Class clazz, int index) { Type genType = clazz.getGenericSuperclass(); if (genType instanceof ParameterizedType) { return getGenericParameter((ParameterizedType) genType, index); }/*from w w w . j a v a 2s . c o m*/ return null; } public static <T> Class<T> getGenericParameter(Field field, int index) { Type genType = field.getGenericType(); if (genType instanceof ParameterizedType) { return getGenericParameter((ParameterizedType) genType, index); } return null; } public static <T> Class<T> getGenericParameter(Method method, int index) { Type genType = method.getGenericReturnType(); if (genType instanceof ParameterizedType) { return getGenericParameter((ParameterizedType) genType, index); } return null; } private static <T> Class<T> getGenericParameter(ParameterizedType type, int index) { Type param = type.getActualTypeArguments()[index]; if (param instanceof Class) { return (Class) param; } return null; } }