Mechanism in Java compiler to substitute method name as literal string
<p>Is there a keyword (or equivalent) in Java that the compiler substitues with the name of the method (and/or class, etc) that the keyword appears in?  This would be similar to the</p>

<pre><code>__FUNCTION__
</code></pre>

<p>macro is C/C++.</p>

<p>I know Java "doesn't support macros", but I'm not asking for user #define'able macros, just a small set of keywords that are replaced with literal strings that the compiler knows.</p>

<p>I know there are methods to get the method a piece of code appears in (<a href="http://www.rgagnon.com/javadetails/java-0420.html" rel="nofollow">http://www.rgagnon.com/javadetails/java-0420.html</a>) but I'm assuming these are not cost-free.  Not surprisingly, if this functionality exists I'd like to use it in tracing, so it really does need to have zero cost or very close to it.</p>

<p>I guess this would be up to the compiler implementation, so maybe my question is whether the usual Java compilers (whatever comes with the JDK) support this.</p>

<p>If not, I fail to understand why this isn't available since it seems useful and I assume it would be trivial for the compiler to provide since surely it knows the method name of the code it's compiling.</p>
