查找在提供的类实现的单个接口上声明的泛型类型。
//package com.nowjava; /** from 时 代 J a v a**/ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { /** * Finds the generic type declared on a single interface implemented by the provided class. * @param clazz the class on which we want to find the generic type. * @return the actual type declared on the provided generic interface. */ public static Class<?> getDeclaredGenericType(Class<?> clazz, Class<?> genericInterface) { Type[] genericInterfaces = clazz.getGenericInterfaces(); for (Type genericType : genericInterfaces) { if (genericType instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType) genericType; if (paramType.getRawType().equals(genericInterface)) {