In a class, I am trying to determine who initially invoked the call chain by using the Thread's stack trace:
StackTraceElement trace = Thread.getStackTrace();
for (int index = 3; index < trace.length; index++ ) {
String className = trace[index].getClassName();
Now I know that the call will always be initiated by the super type MyObject, but I would like to know which subclass actually started the call for logging / auditing purposes.
I am first trying to see if I can logically match superclasses, but even that is failing; I have tried all 4 of the following, but they all seem to return false:
By single-stepping, I can see that I am in the loop with the proper className which is my child that extends MyObject
if (Class.forName(className).isAssignableFrom(MyObject.class)) {
if (MyObject.isAssignableFrom(Class.forName(className))) {
if (Class.forName(className).instanaceOf(MyObject.class)) {
if (MyObject.instanaceOf(Class.forName(className))) {
How else could I test if the class name that I have extends a certain parent?