StackWalker.getInstance(Set): This method is available in the java.lang.StackWalker class of Java.
Syntax:
StackWalker java.lang.StackWalker.getInstance(Set<Option> options)
This method takes one argument. This method returns a StackWalker instance with the given options specifying the stack frame information it can access.
If the given options is empty, this StackWalker is configured to skip all hidden frames and no class reference is retained.
Parameters: One parameter is required for this method.
options: stack walking option.
Returns: a StackWalker configured with the given options.
Throws:
1. SecurityException - if a security manager exists and its checkPermission method denies access.
Approach
Java
package com.StackWalker;import java.lang.StackWalker.Option;import java.util.HashSet;import java.util.Set;public class StackWalkergetInstance2 {public static void main(String[] args) {Set<Option> options = new HashSet<>();options.add(Option.RETAIN_CLASS_REFERENCE);options.add(Option.SHOW_HIDDEN_FRAMES);StackWalker stackWalker =StackWalker.getInstance(options);System.out.println(stackWalker);}}
Output:
java.lang.StackWalker@123772c4
Some other methods of StackWalker
forEach(Consumer): This method performs the given action on each element of the StackFrame stream of the current thread, traversing from the top frame of the stack, which is the method calling this forEach method.
getCallerClass(): This method gets the Class object of the caller who invoked the method that invoked getCallerClass.
StackWalker.getInstance(): This method returns a StackWalker instance.
StackWalker.getInstance(Set): This method returns a StackWalker instance with the given options specifying the stack frame information it can access.
StackWalker.getInstance(Option): This method returns a StackWalker instance with the given option specifying the stack frame information it can access.
StackWalker.getInstance(Set, int): This method returns a StackWalker instance with the given options specifying the stack frame information it can access.
walk(Function): This method applies the given function to the stream of StackFramesfor the current thread, traversing from the top frame of the stack, which is the method calling this walk method.
No comments:
Post a Comment