StackTrace
2019-04-17 本文已影响0人
JaedenKil
import java.util.ArrayList;
public class PrefixDemo {
public static void main(String[] args) {
goo();
}
private static ArrayList<String> getName() {
ArrayList<String> arr = new ArrayList<>();
StackTraceElement[] s = Thread.currentThread().getStackTrace();
for (StackTraceElement value : s) {
arr.add(value.getMethodName());
}
return arr;
}
private static void foo() {
ArrayList<String> prefix = getName();
for (String str : prefix) {
System.out.println("Method name is: '" + str + "'.");
}
}
private static void goo() {
foo();
}
}
Method name is: 'getStackTrace'.
Method name is: 'getName'.
Method name is: 'foo'.
Method name is: 'goo'.
Method name is: 'main'.