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; } }