Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.4k points)

Is there a way to get the name of the currently executing method in Java?

1 Answer

0 votes
by (46k points)

You can  check out  Thread.currentThread().getStackTrace() it will normally include the method you’re calling 

For instance:

public Thread​(ThreadGroup group,

              Runnable target,

              String name,

              long stackSize,

              boolean inheritThreadLocals)

And here are a few lines from Java docs

Some virtual machines may, under some circumstances, omit one or more stack frames from the stack trace. In the extreme case, a virtual machine that has no stack trace information concerning this thread is permitted to return a zero-length array from this method.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...