使用Reflection获取Interface或Abstract类的所有方法

Rne*_*net 5 java reflection

如何在接口/抽象类上使用反射来获取其所有方法?

Joh*_*erg 15

例如,

MyInterfaceOrAbstractClass.class.getDeclaredMethods();
Run Code Online (Sandbox Code Playgroud)

  • @Peter,当然你的意思是相反 (3认同)

tim*_*ooo 6

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());
}
Run Code Online (Sandbox Code Playgroud)