How to run all methods with a given annotation?

后端 未结 3 1607
说谎
说谎 2021-02-06 18:11

This is what I want to happen:

public class MainClass {
    public static void main(String args[]) { 
        run @mod(); // run all methods annotated with @mod          


        
3条回答
  •  感动是毒
    2021-02-06 18:51

    Here's an example using an open source library I have published recently, called Reflect:

    List methods = Reflect.on(someClass).methods().annotatedWith(mod.class);
    for (Method m : methods) {
      m.invoke(null);
    }
    

    Maven Dependency:

    
        org.pacesys
        reflect
        1.0.0
    
    

    More Recipes found at: https://github.com/gondor/reflect

提交回复
热议问题