Get Caller Class Name
Get the name of the Java Class that calls this method.
Javadoc available at https://www.javatapas.com/docs/javatapas/lang/GetCallerClassName.html
public static String getCallerClassName() {
String className = null;
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
for (int i = 1; i < elements.length; i++) {
StackTraceElement element = elements[i];
if (!element.getClassName().equals(MethodHandles.lookup().lookupClass().getName()) && element.getClassName().indexOf("java.lang.Thread") != 0) {className = element.getClassName();}
}
return className;
}