http://tidus2005.iteye.com/blog/460648
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();// 获得当前的方法名
本文介绍了一种在Java中获取调用堆栈信息的方法,通过构造一个未捕获的异常来获取当前方法的调用堆栈,并从中抽取类名、方法名及行号等关键信息。


被折叠的 条评论
为什么被折叠?



