Java取得メソッド呼び出し者名

586 ワード

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());

	}

}