I would like to write a code internal to my method that print which method/class has invoked it.
(My assumption is that I can’t change anything but my method..)
How about other programming languages?
EDIT: Thanks guys, how about JavaScript? python? C++?
This is specific to Java.
You can use
Thread.currentThread().getStackTrace(). This will return an array ofStackTraceElements.The 2nd element in the array will be the calling method.
Example: