Java 获得方法调用者名称

public static void getCaller() {

	StackTraceElement[] stack = (new Throwable()).getStackTrace();

	for (int i = 0; i < stack.length; i  ) {

		StackTraceElement ste = stack[i];

		System.out.println(ste.getClassName()   "."   ste.getMethodName()   "(...);");

		System.out.println(i   "--"   ste.getMethodName());

		System.out.println(i   "--"   ste.getFileName());

		System.out.println(i   "--"   ste.getLineNumber());

	}

}

你可能感兴趣的:(java)