public class ClassUtils { /** * 获得当前方法名 * @return */ public static String getCurrentMethodName() { int level = 1; StackTraceElement[] stacks = new Throwable().getStackTrace(); String methodName = stacks[level].getMethodName(); return methodName; } /** * 获得当前类名 * @return */ public static String getCurrentClassName() { int level = 1; StackTraceElement[] stacks = new Throwable().getStackTrace(); String className = stacks[level].getClassName(); return className; } }
转载于:https://my.oschina.net/u/1177694/blog/820315