getCallerClass
Retrieves the class of the method's immediate caller.
This utility function uses a StackWalker
instance to walk the call stack and retrieve the class that invoked the current method. The depth
parameter determines how far back in the call stack the search proceeds, relative to the default offset used internally.
This function is useful for tasks such as debugging, logging, or implementing caller-sensitive behaviors.
Note: Invoking this function may have performance overhead depending on the depth of the stack and the number of elements traversed.
Return
The Class
object of the caller, or null if no caller is found in the stack at the specified depth.
Retrieves the class of a caller at a specific depth in the call stack.
This utility function uses a StackWalker
instance to walk the call stack and retrieve the class that invoked the current method at a specified depth. The depth
parameter determines how many levels to move up in the stack to locate the desired caller.
This function is commonly used for tasks such as debugging, logging, or implementing caller-sensitive behaviors.
Note: The default offset of 3 accounts for the internal implementation of the stack walker.
Return
The Class
object of the caller at the specified depth, or null if no class is found at that depth in the call stack.
Parameters
The number of levels to walk up the call stack to locate the desired caller. A value of 0 corresponds to the immediate caller, while higher values move further up the stack.