获取当前正在执行的方法的名称 [英] Getting the name of the currently executing method

查看:40
本文介绍了获取当前正在执行的方法的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Java 中获取当前正在执行的方法的名称?

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

推荐答案

线程.currentThread().getStackTrace() 通常会包含您从中调用它的方法,但是有陷阱(参见 Javadoc):

在某些情况下,某些虚拟机可能会从堆栈跟踪中省略一个或多个堆栈帧.在极端情况下,允许没有与此线程相关的堆栈跟踪信息的虚拟机从此方法返回零长度数组.

Some virtual machines may, under some circumstances, omit one or more stack frames from the stack trace. In the extreme case, a virtual machine that has no stack trace information concerning this thread is permitted to return a zero-length array from this method.

这篇关于获取当前正在执行的方法的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆