Java: How to get the caller function name

前端 未结 6 1165
情深已故
情深已故 2021-02-05 01:56

To fix a test case I need to identify whether the function is called from a particular caller function. I can\'t afford to add a boolean parameter because it would break the int

6条回答
  •  梦毁少年i
    2021-02-05 02:32

    You could try

    StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
    StackTraceElement e = stacktrace[2];//maybe this number needs to be corrected
    String methodName = e.getMethodName();
    

提交回复
热议问题