getStackTrace
method5
method4
method3
method2
method1
main
invoke0
invoke
invoke
invoke
callMainMethod
execute
execute
main
main
getStackTrace
method5
method5
method4
method3
method2
method1
main
invoke0
invoke
invoke
invoke
callMainMethod
execute
execute
main
main
getStackTrace
method5
method5
method5
method4
method3
method2
method1
main
invoke0
invoke
invoke
invoke
callMainMethod
execute
и тд.
package com.javarush.task.task09.task0901;
/*
Возвращаем StackTrace
*/
public class Solution {
public static void main(String[] args) {
method1();
}
public static StackTraceElement[] method1() {
method2();
return method1();
}
public static StackTraceElement[] method2() {
method3();
return method2();
}
public static StackTraceElement[] method3() {
method4();
return method3();
}
public static StackTraceElement[] method4() {
method5();
return method4();
}
public static StackTraceElement[] method5() {
StackTraceElement[] stackTraceElement = Thread.currentThread().getStackTrace();
for(StackTraceElement element : stackTraceElement){
System.out.println(element.getMethodName());
}
return method5();
}
}