I have class X and in it there is a static method called doStuff() and I have several other classes with methods that call to doStuff() for some reason. Is there a way for example to have a print method in doStuff() that prints from which methods and classes it is called ?
I have class X and in it there is a static method called doStuff()
Share
Yes:
new Throwable().getStackTrace()returns array ofStackTraceElement. Index number 1 is your caller.