我知道这是非常小的,但在每个类的顶部我最终复制和粘贴,然后更改以下代码行.
private static final String TAG = MyClass.class.getName();
Run Code Online (Sandbox Code Playgroud)
我想做的是每次复制时都不必修改MyClass位.
即我想写这个.
private static final String TAG = this.class.getName();
Run Code Online (Sandbox Code Playgroud)
但显然现在没有这个.我知道它很小,但我通常从SO答案中学到一些东西,并且确实学到了一些好东西,只是在寻找是否已有答案.
您可以定义一个名为的Eclipse模板,tag例如:
private static final String TAG = ${enclosing_type}.class.getName();
Run Code Online (Sandbox Code Playgroud)
然后,键入tag后跟,Ctrl+Space它将插入此语句.
我使用这种方法在我的类中声明记录器.
或者,查询当前线程的堆栈跟踪:
private static final String TAG = Thread.currentThread().getStackTrace()[1].getClassName();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
893 次 |
| 最近记录: |