return Thread.currentThread().getStackTrace()[2].getMethodName();
这里 为什么要加 这个 [2] 呀
求大佬救救迷茫的我
已解决
评论 (3)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
Gellert Varga
16 二月 2022, 21:43解决方法
Because of:
"每个方法都应返回调用它的方法的名称"
Thread.currentThread().getStackTrace() is an array.
The element of this array with index 0 represents the getStackTrace() method itself.
An element of this array with index 1 represents the method we are currently in. I would name this the current method. This is the method that called getStackTrace().
The index 2 element of this array is the method that called the current method. (And this is what the task asks us.)
You can try it all yourself: just print the method name of the element 0, the 1, the 2, etc.
+5
代码没写完啊~
17 二月 2022, 01:09
感谢大佬💪
0
Gellert Varga
17 二月 2022, 13:17
:-)
0