Java, method name via reflection for logging

折月煮酒 提交于 2019-12-24 15:19:07

问题


Working on a quick logging utility method. Normally I would use Aspects for this but working in the Android SDK where there isnt support for that.

How would I go about grabbing a method name in a generic way using reflection?

Also any performance hit in java with reflection ?


回答1:


Something like this will probably work:

Thread.currentThread().getStackTrace()[0].getMethodName()


来源:https://stackoverflow.com/questions/28948076/java-method-name-via-reflection-for-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!