To do this correctly, you must provide a C-method with this information, for example, using an enumeration parameter or a class:
public void init(Object otherArg, Class<?> caller) { ... }
or
public void init(Object otherArg, CallerEnum caller) { ... }
But if you don't care, there is another way to use stack trace. Look at Get the current stack trace in Java and use a second StackTraceElement from the top of the stack to get a method called the current one.
source share