通过类上的索引找到通用声明。
//package com.nowjava; /** 来 自 n o w j a v a . c o m - 时 代 Java **/ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { public static Class<?> getGenericClass(Class<?> clazz) { return getGenericClass(clazz, 0); } /** * 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) { /* from 时 代 J a v a 公 众 号 */ Type[] params = ((ParameterizedType) genType) .getActualTypeArguments();