/** * Returns the caller class of the calling method.<br> For example: <br> A.calling() -> B.called() B.called() * -> * getCallerClass(): A <br> If a thread context classloader is defined, it will be used for loading the class, * otherwise the default class loader is used. * * @return the class of the calling method's class */ public static Class<?> getCallerClass() { final StackTraceElement[] stElements = Thread.currentThread().getStackTrace(); try { final StackTraceElement caller = findCaller(stElements); return loadClass(caller.getClassName()); } catch (ClassNotFoundException e) { throw new RuntimeException("Could not determine caller class", e); } }