A facility for getting the current method's name
Krystal Mok
rednaxelafx at gmail.com
Tue Sep 27 03:35:56 PDT 2011
Hi Behrang,
This reminds me of how people were looking for a "current class literal",
something like this:
public class Foo {
public static void main(String[] args) {
// don't want to hard code "Foo.class" here
String name = Foo.class.getName();
}
}
and now that JDK7 is out, they've got a new toy that gives them exactly
that:
java.lang.invoke.MethodHandles.lookup().lookupClass()
It's not mean't to be fast when used like this, though.
The same with what you're looking for, but you've already got backtrace
which gives you the correct semantics, just not fast enough, right?
On Mon, Sep 26, 2011 at 7:31 PM, Behrang Saeedzadeh <behrangsa at gmail.com>wrote:
> Sean, Mario,
>
> I am looking for something like JavaScript's arguments.callee.name or
> Ruby's __method__. AFAIK, accessing the current method's name is a
> very cheap operation in JS and Ruby while creating a stack trace is a
> moderately expensive operation in Java.
They don't seem to be expensive in JavaScript or Ruby because those
languages didn't have fast implementations. Once they do (as the current JS
engines and JRuby/Rubinius), this kind of reflective operations will show
their cost.
Regards,
Kris Mok
More information about the jdk8-dev
mailing list