R
Rhino
I recently read a post (via Google) that said it is usually a bad idea to
use reflection and that it is only rarely necessary since there are better
ways to do most things.
That has me wondering about something. When I handle an error in my
programs, I always want to obtain the name of the current class and the name
of the method that is executing for my error handling logic so that this
information can be logged and/or displayed to the user. For years now, I've
been getting the class name via getClass().getName(), i.e. via Reflection,
and I've hard-coded my method name in each method, e.g. String METHOD_NAME =
"foo()".
In light of the claim that reflection is usually the wrong approach to use,
what is the RIGHT approach to use in determining the name of the current
class and method? Or is my approach reasonable for my purposes?
I would especially love to hear a technique that would let me determine the
current method's name at runtime without having to hard-code it in each
method the way I am doing now; that has always struck me as a kludge.
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare
use reflection and that it is only rarely necessary since there are better
ways to do most things.
That has me wondering about something. When I handle an error in my
programs, I always want to obtain the name of the current class and the name
of the method that is executing for my error handling logic so that this
information can be logged and/or displayed to the user. For years now, I've
been getting the class name via getClass().getName(), i.e. via Reflection,
and I've hard-coded my method name in each method, e.g. String METHOD_NAME =
"foo()".
In light of the claim that reflection is usually the wrong approach to use,
what is the RIGHT approach to use in determining the name of the current
class and method? Or is my approach reasonable for my purposes?
I would especially love to hear a technique that would let me determine the
current method's name at runtime without having to hard-code it in each
method the way I am doing now; that has always struck me as a kludge.
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare