Sometimes you want to know which class/method called your function. Starting with Java 1.4, java.lang.StackTraceElement provides an easy way to accomplish this. Here is how
StackTraceElement telements = new Exception().getStackTrace();
String callerClass = telements.getClassName();
String callerMethod = telements.getMethodName();
The array's 0th item is your method and 1st item is the method that called your method.
Grigori Kozintsev - Gamlet AKA Hamlet [+extras] (1964)
11 months ago