Как мне казалось, порядок отработки такой :
1. мэин
2. метод 1
...
...
...
3.метод 5
4. стэктрейс
Соответственно если вывожу наоборот, метод 5 будет [1], так как стек трейс [0]
Но проверку не проходит
package com.javarush.task.task09.task0903;
/*
Кто меня вызывал?
*/
public class Solution {
public static void main(String[] args) {
method1();
}
public static int method1() {
method2();
return Thread.currentThread().getStackTrace()[5].getLineNumber();
}
public static int method2() {
method3();
return Thread.currentThread().getStackTrace()[4].getLineNumber();
}
public static int method3() {
method4();
return Thread.currentThread().getStackTrace()[3].getLineNumber();
}
public static int method4() {
method5();
return Thread.currentThread().getStackTrace()[2].getLineNumber();
}
public static int method5() {
return Thread.currentThread().getStackTrace()[1].getLineNumber();
}
}