So, I have this class and I want to print which methods were called. When I run it it prints only trace and main but not method1 and method2. How can I change it so it would print method1 and method2, the methods called from 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());
}
}