public class A {
public static void main(String[] args) {
n();
}
public static void n()
{
getCaller();
}
public static void getCaller()
{
StackTraceElement stack[] = (new Throwable()).getStackTrace();
for (int i = 0; i < stack.length; i++)
{
StackTraceElement s = stack[i];
System.out.format("Class:%d\t%s\n", i, s.getClass());//类类型
System.out.format("ClassName:%d\t%s\n", i, s.getClassName());//类名
System.out.format("MethodName:%d\t%s\n", i, s.getMethodName());//方法名
System.out.format("FileName:%d\t%s\n", i, s.getFileName());//文件名
System.out.format("LineNumber:%d\t%s\n", i, s.getLineNumber());//行数
System.out.println("-------------------------------------------");//行数
}
}
}
java获取代码调用位置信息
最新推荐文章于 2024-06-29 03:41:40 发布