0
是否可以在Groovy代码中获取当前方法的名称?在运行时获取当前调用方法的名称
def myMethod() {
// want to get the string myMethod here
}
感谢
是否可以在Groovy代码中获取当前方法的名称?在运行时获取当前调用方法的名称
def myMethod() {
// want to get the string myMethod here
}
感谢
Tim_yates为您提供了一个链接到通用的解决方案。
这是获取方法名称的较短方法。为了清晰起见,可以优化,放弃。
class A {
def myMethod() {
for (m in new Throwable().stackTrace) {
if (m.className == this.class.name)
return m.methodName
}
}
}
println new A().myMethod()