I have a classes in my project with the following structure
Class A Class B Class C
Under Class C.... I have the function mention below
public static String getCallingClassname() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[4];
String classname = e.getClassName();
return classname; }
Class A is my main file from where I execute the script. Now, from Class A, I calls the function of Class B which in turn calls the getCallingClassname() method of Class C. In order to get the classname of Class A, I have used the index no as 4. Problem is, there are many times when Class A directly calls the getCallingClassname() method of Class C, so in that case index 4 gives a wrong value.
Is there any method, through which I can always get the Parent Classname i.e. Class A in my example above ?
Thanks