Created
April 25, 2016 13:08
-
-
Save jyeary/065160d2368a8ad1d9b8cb74fc72ef60 to your computer and use it in GitHub Desktop.
Determines the calling Class within a method, and returns the name of the Class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Utils { | |
| /** | |
| * Default Constructor | |
| */ | |
| public Utils() { | |
| } | |
| /** | |
| * Determines the caller class. This method should be invoked within a | |
| * method body to determine which {@code Class} called it. | |
| * | |
| * @return The name of the {@code Class} which invoked the method. | |
| */ | |
| public static String getCallerClazz() { | |
| StackTraceElement[] stElements = Thread.currentThread().getStackTrace(); | |
| StackTraceElement st = stElements[stElements.length - 1]; | |
| return st.getClassName(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment