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