直接上代码:
static class Test1<Test4> implements Test3<Test2,Test5>{ }
interface Test3<T,V>{}
class Test2{}
class Test4{}
class Test5{}
public static void main(String[] args) throws Exception {
Test1 t1 = new Test1();
Class clz = t1.getClass();
System.out.println("clz:" + clz);
System.out.println("clz:" + clz.getGenericSuperclass());
Type[] t = clz.getGenericInterfaces();
if (t != null && t.length != 0) {
System.out.println("clz interface: " + t.length);
for (int i = 0; i < t.length; i++) {
if (t[i] instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) t[i];
System.out.println("interface is:"+ parameterizedType.getTypeName());
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
if (actualTypeArguments != null && actualTypeArguments.length != 0) {
for (int j = 0; j < actualTypeArguments.length; j++) {
Class actualTypeArgument = (Class)parameterizedType.getActualTypeArguments()[j];
System.out.println("type is : " + parameterizedType.getActualTypeArguments()[j].getTypeName());
}
}
}
}
}
}