简体   繁体   中英

How can I call a class which will get the name of the class which is being invoked?

I have multiple classes here and I need to know which class is being invoked. From searching I got an idea of how I might do this which suggests I do this:

StackTraceElement[] stElements = Thread.currentThread().getStackTrace();
for (int i=1; i<stElements.length; i++) {
    StackTraceElement ste = stElements[i];
    String className = ste.getClassName();
}

This gets me the class names but the problem is where do I should write this code so that I can get the name of the class which is being executed all the time in my app.

您可以在ste.getClassName()之后添加以下行,以查看类名是什么:

System.out.println(className);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM