全屏
java.lang.Class.getGenericInterfaces()返回表示当前对象所表示的类或接口直接实现的接口类型。
声明
以下是java.lang.Class.getGenericInterfaces()方法的声明public Type[] getGenericInterfaces()
参数NA
返回值
此方法返回这个类中实现接口的数组。
异常GenericSignatureFormatError -- 如果泛型类的签名不符合Java虚拟机规范中指定的格式,第3版。
TypeNotPresentException -- 如果任何通用的超接口中是指一种不存在的类型声明
MalformedParameterizedTypeException -- 如果有一般超接口的引用参数化类型不能被实例化的理由。
例子
下面的例子显示java.lang.Class.getGenericInterfaces()方法的使用。package cn.sxt;
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...
分享到:
0评论