forEach(Consumer): This method is available in the java.lang.StackWalker class of Java.
Syntax:
void java.lang.StackWalker.forEach(Consumer<? super StackFrame> action)
This method takes one argument. This method performs the given action on each element of StackFrame stream of the current thread, traversing from the top frame of the stack,which is the method calling this forEach method.
Parameters: One parameter is required for this method.
action: an action to be performed on each StackFrame of the stack of the current thread.
Returns: NA
Exceptions: NA
Approach
Java
package com.StackWalker;public class StackWalkerforEach {public static void main(String[] args) {StackWalker stackWalker = StackWalker.getInstance();stackWalker.forEach(n -> System.out.println(n));}}
Output:
com.StackWalker.StackWalkerforEach.main(StackWalkerforEach.java:8)
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