Java tutorial
//package com.java2s; //License from project: Apache License import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { public static Type[] getGenericType(Class<?> clazz, Class<?> interfaceClazz) { Type st = clazz.getGenericSuperclass(); Type[] ret = getActualTypeArguments(interfaceClazz, st); if (ret != null) return ret; for (Type t : clazz.getGenericInterfaces()) { ret = getActualTypeArguments(interfaceClazz, t); if (ret != null) return ret; } Class<?> s = clazz.getSuperclass(); if (s == null || clazz.equals(s.getClass())) return new Type[0]; return getGenericType(s, interfaceClazz); } private static Type[] getActualTypeArguments(Class<?> type, Type t) { if (t != null && t instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) t; if (pt.getRawType().equals(type)) return ((ParameterizedType) t).getActualTypeArguments(); } return null; } }