Here you can find the source of getGenericClass(Class clazz, int index)
Parameter | Description |
---|---|
clazz | clazz The class to introspect |
index | the Index of the generic ddeclaration,start from 0. |
public static Class getGenericClass(Class clazz, int index)
//package com.java2s; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { /**// w ww. j a v a 2s .c o m * Locates generic declaration by index on a class. * * @param clazz clazz The class to introspect * @param index the Index of the generic ddeclaration,start from 0. */ public static Class getGenericClass(Class clazz, int index) { Type genType = clazz.getGenericSuperclass(); if (genType instanceof ParameterizedType) { Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if ((params != null) && (params.length >= (index - 1))) { return (Class) params[index]; } } return null; } }