Getting the name of the currently executing method

前端 未结 22 2203
闹比i
闹比i 2020-11-22 03:33

Is there a way to get the name of the currently executing method in Java?

22条回答
  •  伪装坚强ぢ
    2020-11-22 04:33

     public class SomeClass {
       public void foo(){
          class Local {};
          String name = Local.class.getEnclosingMethod().getName();
       }
     }
    

    name will have value foo.

提交回复
热议问题