java獲取當前類名和方法名
Description Below I present you two different ways to get the current Class: Using Thread ...
Description Below I present you two different ways to get the current Class: Using Thread ...
獲取class名: this.getClass().getName(); 或者 Thread.currentThread().getStackTrace()[1].getClassName(); 獲取方法名: Thread.currentThread().getStackTrace ...
1、獲取當前類名: this.getClass().getSimpleName() 也可以 2、獲取當前方法名: ...
很簡單,直接看代碼: ...
代碼如下: ...
獲取當前方法的名稱空間、類名和方法名稱 獲取調用者類名和方法名 ...
在 JAVA 程序有時需要獲取當前代碼位置, 於是就利用 Thread.currentThread().getStackTrace() 寫了下面這個工具類, 用來獲取當前執行位置處代碼的文件名/類名/方法名/行號. 當然通過 new Throwable().getStackTrace ...