Getting the name of the currently executing method

前端 未结 22 2239
闹比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:14

    public static String getCurrentMethodName() {
            return Thread.currentThread().getStackTrace()[2].getClassName() + "." + Thread.currentThread().getStackTrace()[2].getMethodName();
        }
    

提交回复
热议问题