
正文
JAVA中获取当前运行的类名,方法名,行数
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
JAVA中获取当前运行的类名,方法名,行数
public static String getTraceInfo(){
StringBuffer sb = new StringBuffer(); StackTraceElement[] stacks = new Throwable().getStackTrace();
int stacksLen = stacks.length;
sb.append("class: " ).append(stacks[1].getClassName()).append("; method: ").append(stacks[1].getMethodName()).append("; number: ").append(stacks[1].getLineNumber()); return sb.toString();
} String _methodName = new Exception().getStackTrace()[1].getMethodName();// 获得调用者的方法名 String _thisMethodName = new Exception().getStackTrace()[0].getMethodName();// 获得当前的方法名






