Getting the caller method details using Java

1
2
3
4
5
6
7
8
9
10
 public static String getCallerClassName() {
        StackTraceElement[] stElements = Thread.currentThread().getStackTrace();
        for (int i=1; i<stElements.length; i++) {
            StackTraceElement ste = stElements[i];
            if (!ste.getClassName().equals(YOUR_CURRENTCLASS.class.getName()) && ste.getClassName().indexOf("java.lang.Thread")!=0) {
                return ste.getClassName()+"."+ ste.getMethodName()+"()";
            }
        }
        return null;
     }
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


3 − one =