Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
目前我这样写我的日志语句:
Log.i(TAG, MyClass.class.getSimpleName() + "#methodName" + someThing);
有没有办法引用类似于Class's getSimpleName()不涉及硬编码的方法名称String?
Class's
getSimpleName()
String
您可以使用Thread.currentThread().getStackTrace()[1].getMethodName();
Thread.currentThread().getStackTrace()[1].getMethodName();
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); Log.i(TAG, MyClass.class.getSimpleName() + methodName + someThing);