Java,通过反射进行记录的方法名称 [英] Java, method name via reflection for logging

查看:71
本文介绍了Java,通过反射进行记录的方法名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

研究快速记录实用程序方法.通常,我会为此使用Aspects,但可以在不支持该功能的Android SDK中进行操作.

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?

在Java中使用反射是否还会影响性能?

Also any performance hit in java with reflection ?

推荐答案

类似的方法可能会起作用:

Something like this will probably work:

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

这篇关于Java,通过反射进行记录的方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆