I run the code on VSCode and IntelliJ and I get the following output:
getStackTrace
getStackTraceDepth
main
Stack Trace Depth:3
When I run it on CodeGym I get:
getStackTrace
getStackTraceDepth
main
invoke0
invoke
invoke
invoke
callMainMethod
execute
execute
main
main
Stack Trace Depth:12
Any ideas why I get different output on IntelliJ/VSCode from CG ?
package en.codegym.task.jdk13.task09.task0905;
/*
The method returns a result — the depth of its stack trace
*/
public class Solution {
public static void main(String[] args) {
int deep = getStackTraceDepth();
}
public static int getStackTraceDepth() {
int stackTraceDepth = Thread.currentThread().getStackTrace().length;
for (int i = 0; i < stackTraceDepth; i++) {
System.out.println(Thread.currentThread().getStackTrace()[i].getMethodName());
}
System.out.println("Stack Trace Depth:" + (stackTraceDepth));
return stackTraceDepth;
}
}