比如一个类中有一个函数 void functionName() {
callOtherFunction("functionName");
}有没有办法取得函数名称字符串呢?在callOtherFunction如果不通过指定的字符串传递能知道调用者是哪个函数吗?
callOtherFunction("functionName");
}有没有办法取得函数名称字符串呢?在callOtherFunction如果不通过指定的字符串传递能知道调用者是哪个函数吗?
根据当前的堆栈信息可以找出。
void functionName() {
StackTraceElement[] sts = new Throwable().getStackTrace();
String methodName = sts[0].getMethodName();
callOtherFunction(methodName);
}