Getting the name of the currently executing method

前端 未结 22 2597
闹比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

    Use the following Code :

        StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
        StackTraceElement e = stacktrace[1];//coz 0th will be getStackTrace so 1st
        String methodName = e.getMethodName();
        System.out.println(methodName);
    

提交回复
热议问题