A facility for getting the current method's name
Behrang Saeedzadeh
behrangsa at gmail.com
Sun Sep 25 19:51:42 PDT 2011
Hi,
Would it be possible to add a feature to get the current method's name
in an efficient without first creating a stack trace?
Something like:
public void foo() {
String methodName = Method.getCurrentMethod().getName();
assert methodName.equals("foo");
}
This would make writing code like this more elegant and refactor-friendly:
public void init(Bar bar) {
if (this.bar != null) {
throw new IllegalStateException(Method.getCurrentMethod().getName()
+ " should not be called more than once");
}
this.bar = bar;
}
Cheers,
Behrang Saeedzadeh
http://www.behrang.org
More information about the jdk8-dev
mailing list