Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java equivalent to __func__

#include <stdio.h>
void someFunc(void) {
  printf("%s\n"), __func__);
}

Each time the function is called it will print:

someFunc

What is the java equivalent?

I have found

(new Exception()).getStackTrace()[0].getMethodName()

And

java.lang.Thread.currentThread().getStackTrace()[1].getMethodName()

But these just seem ridiculous, is there an easier way?

like image 813
NorthIsUp Avatar asked Mar 26 '11 00:03

NorthIsUp


1 Answers

No, there's no easier way. As Java doesn't have a macro facility, there's nothing directly equivalent to the C++ version.

like image 197
Ernest Friedman-Hill Avatar answered Sep 23 '22 16:09

Ernest Friedman-Hill