所以,我有这个类,我想打印调用哪些方法.当我运行它时,它只打印trace和main,但不打印method1和method2.如何更改它以便打印method1和method2,从main调用的方法?
public class SomeClass
{
public void method1() {}
public void method2() {}
public static void main(String args[]) throws Throwable
{
SomeClass c = new SomeClass();
c.method1();
c.method2();
SomeClass.trace();
}
public static void trace() throws Throwable
{
Throwable t = new Throwable();
StackTraceElement[] stack = t.getStackTrace();
for(StackTraceElement s : stack)
System.out.println(s.getMethodName());
}
}
Run Code Online (Sandbox Code Playgroud)