Here you can find the source of getGenericSuperType(Class extends T> subclass, Class extends T> classWithParameter)
Parameter | Description |
---|---|
T | a parameter |
subclass | a parameter |
classWithParameter | a parameter |
public static <T> Type getGenericSuperType(Class<? extends T> subclass, Class<? extends T> classWithParameter)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Type; public class Main { /**/*from ww w. ja v a 2s . co m*/ * returns either the generic superclass or a generic interface, but only when it is assignable from the typed * classWithParameter argument * * @param <T> * @param subclass * @param classWithParameter * @return */ public static <T> Type getGenericSuperType(Class<? extends T> subclass, Class<? extends T> classWithParameter) { if (subclass.getSuperclass() != null && classWithParameter.isAssignableFrom(subclass.getSuperclass())) { return subclass.getGenericSuperclass(); } else { int i = 0; for (Class in : subclass.getInterfaces()) { if (classWithParameter.isAssignableFrom(in)) { return subclass.getGenericInterfaces()[i]; } i++; } return null; } } }