i try my best to understand but ...... :(
package com.codegym.task.task09.task0902;
/*
Stack trace revisited
*/
public class Solution {
public static void main(String[] args) throws Exception {
method1();
}
public static String method1() {
method2();
//write your code here
// StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
// StackTraceElement e = stacktrace[4];//coz 0th will be getStackTrace so 1st
// String methodName = e.getMethodName();
// System.out.println(methodName);
return Thread.currentThread().getStackTrace()[0].getClassName();
}
public static String method2() {
method3();
//write your code here
// StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
// StackTraceElement e = stacktrace[3];//coz 0th will be getStackTrace so 1st
// String methodName = e.getMethodName();
// System.out.println(methodName);
return Thread.currentThread().getStackTrace()[1].getMethodName();
}
public static String method3() {
method4();
//write your code here
// StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
// StackTraceElement e = stacktrace[2];//coz 0th will be getStackTrace so 1st
// String methodName = e.getMethodName();
// System.out.println(methodName);
return Thread.currentThread().getStackTrace()[2].getMethodName();
}
public static String method4() {
method5();
//write your code here
// StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
// StackTraceElement e = stacktrace[1];//coz 0th will be getStackTrace so 1st
// String methodName = e.getMethodName();
// System.out.println(methodName);
return Thread.currentThread().getStackTrace()[3].getMethodName();
}
public static String method5() {
//write your code here
// StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
// StackTraceElement e = stacktrace[0];//coz 0th will be getStackTrace so 1st
// String methodName = e.getMethodName();
// System.out.println(methodName);
return Thread.currentThread().getStackTrace()[4].getMethodName();
}
}