Wednesday, November 14, 2007

How can I find what class or method is calling this method? Java

To do it, use this wherever you need to know who is calling the current method:
{..
String className = new Throwable().getStackTrace()[1].getClassName();
String methodName = new Throwable().getStackTrace()[1].getMethodName();
..}