Class StackWalkerExamples

java.lang.Object
net.jrodolfo.java_evolution.java09.StackWalkerExamples

public class StackWalkerExamples extends Object
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 Details

    • StackWalkerExamples

      public StackWalkerExamples()
  • Method Details

    • callerMethodName

      public String callerMethodName()
      Finds the method that called this method.
      Returns:
      the caller method name
    • callerClassName

      public String callerClassName()
      Finds the class that called this method.
      Returns:
      the caller class name