How to get string name of a method in java?

前端 未结 7 651
梦谈多话
梦谈多话 2020-11-29 06:10

How can I find out through reflection what is the string name of the method?

For example given:

class Car{
   public void getFoo(){
   }
}

相关标签:
7条回答
  • 2020-11-29 06:43

    Look into this thread:

    Getting the name of the currently executing method

    It offers some more solutions - for example:

    String name = new Object(){}.getClass().getEnclosingMethod().getName();
    
    0 讨论(0)
提交回复
热议问题