AlexVPerl
AlexVPerl

Reputation: 7996

Java, method name via reflection for logging

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 ?

Upvotes: 2

Views: 1054

Answers (1)

toadzky
toadzky

Reputation: 3846

Something like this will probably work:

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

Upvotes: 3

Related Questions