Java.lang.Class.getGenericInterfaces() 方法
描述
java.lang.Class.getGenericInterfaces() 返回表示由该对象表示的类或接口直接实现的接口的类型。
声明
以下是 java.lang.Class.getGenericInterfaces() 方法的声明。
public Type[] getGenericInterfaces()
参数
NA
返回值
该方法返回该类实现的接口数组。
异常
GenericSignatureFormatError − 如果泛型类签名不符合 Java 虚拟机规范第 3 版中指定的格式。
TypeNotPresentException − 如果任何泛型超接口引用了不存在的类型声明
MalformedParameterizedTypeException − 如果任何通用超接口引用了由于任何原因无法实例化的参数化类型。
示例
下面的例子展示了 java.lang.Class.getGenericInterfaces() 方法的使用。
package com.tutorialspoint;
import java.lang.reflect.*;
public class ClassDemo {
public static void main(String []args) {
ClassDemo d = new ClassDemo();
Class c = d.getClass();
Type[] t = c.getGenericInterfaces();
if(t.length != 0) {
for(Type val : t) {
System.out.println(val.toString());
}
} else {
System.out.println("Interfaces are not implemented...");
}
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Interfaces are not implemented...

