3
如何在接口/抽象類上使用反射來獲取其所有方法?使用反射獲取接口或抽象類的所有方法
如何在接口/抽象類上使用反射來獲取其所有方法?使用反射獲取接口或抽象類的所有方法
例如,
MyInterfaceOrAbstractClass.class.getDeclaredMethods();
Class clazz = Something.class;
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
// do what you have to do with the method
System.out.println(method.getName());
}
+1:這會給你的公共方法。你可以使用getMethod()來獲得它的所有方法(你可能需要爲父母做這件事:) – 2011-05-31 09:55:18
或Class.getMethods()? – keuleJ 2011-05-31 09:55:40
@Peter,當然你的意思是相反 – 2011-05-31 09:57:23