How do I get the method name at compile time?
And why has it been difficult for me to figure this out? Why wouldn't Java want me to do this? I don't see any inherent problems with a feature like this, and it's useful for logging method names without duplication between the method signature and the string constant like so:
private void methodName() {
final String MN = "methodName";
...
Someone might change the method name without changing the MN constant, and then I can't find it in the log.
I know Java has a (reflective?) method for doing this, but why anyone would want to over-complicate things and create the possibility of errors with a run-time solution (for this particular problem) is beyond me.
Aucun commentaire:
Enregistrer un commentaire