获取当前运行的类名或者方法

public static String getCurrentMethodName() {
int level = 1;
StackTraceElement[] stacks = new Throwable().getStackTrace();
String methodName = stacks[level].getMethodName();
return methodName;
}

public static String getCurrentClassName() {
int level = 1;
StackTraceElement[] stacks = new Throwable().getStackTrace();
String className = stacks[level].getClassName();
return className;
}

posted @ 2014-11-14 14:42  3H  阅读(253)  评论(0编辑  收藏  举报