Class StackWalkerExamples
java.lang.Object
net.jrodolfo.java_evolution.java09.StackWalkerExamples
Demonstrates
StackWalker, introduced in Java 9.
Before Java 9, stack inspection commonly used
Thread.currentThread().getStackTrace(), which eagerly created an
array and gave limited control over how frames were consumed.
StackWalker solves this by providing a lazy and structured way to inspect stack frames. It is useful for diagnostics, logging, and framework code that needs caller information without eagerly materializing the whole stack.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFinds the class that called this method.Finds the method that called this method.
-
Constructor Details
-
StackWalkerExamples
public StackWalkerExamples()
-
-
Method Details
-
callerMethodName
Finds the method that called this method.- Returns:
- the caller method name
-
callerClassName
Finds the class that called this method.- Returns:
- the caller class name
-