获取当前方法名的方法:
public static String getCurrentMethodName() {
String method = Thread.currentThread().getStackTrace()[3].getMethodName();
return method;
}
调用示例
public static void dosomething() {
String tempMethodName = getCurrentMethodName();
Log.d("test111", "tempMethodName is:" + tempMethodName);
}
public void callInterfaces() {
String tempMethodName = getCurrentMethodName();
Log.d("test111", "tempMethodName is:" + tempMethodName);
}
log输出
10-10 16:23:56.704 32161 32161 D test111 : tempMethodName is:callInterfaces
10-10 16:23:56.727 32161 32161 D test111 : tempMethodName is:dosomething
以dosomething为例的调用栈
index0: VMStack的getThreadStackTrace()
index1: Thread的getStackTrace()
index2: getCurrentMethodName()方法
index3: dosomething()方法
|