How to determine the calling class in Java
String callingClassName =
getCallerClassmethod takes an
intargument where a value of 0 (zero) returns
sun.reflect.Reflection, 1 returns the class of the currently executing method and every increment looks up the call stack.
If you are bothered by the prospect of using a sun.* API, you may (write a utility class to) sub-class the SecurityManager and use its
protected native Class getClassContext()method which returns the call stack. The element at index 0 is the class of the currently executing method, the element at 1 is the caller and so on up the stack.