【发布时间】:2010-09-12 02:36:42
【问题描述】:
我需要判断一个表示一个接口的Class对象是否扩展了另一个接口,即:
package a.b.c.d;
public Interface IMyInterface extends a.b.d.c.ISomeOtherInterface{
}
根据the spec Class.getSuperClass() 将为接口返回null。
如果这个类代表 对象类,一个接口,一个 原始类型或 void,则 null 为 返回。
因此,以下将不起作用。
Class interface = Class.ForName("a.b.c.d.IMyInterface")
Class extendedInterface = interface.getSuperClass();
if(extendedInterface.getName().equals("a.b.d.c.ISomeOtherInterface")){
//do whatever here
}
有什么想法吗?
【问题讨论】:
标签: java reflection interface