Java中獲取當前類名和方法名

String className = this.getClass().getName(); // 包含報名,getSimpleName()爲僅獲取名稱
String methodName = new Exception().getStackTrace()[0].getMethodName();
String msg = String.format("Invoke className: %s, methodName: %s", className, methodName);
System.out.println(msg);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章