Re: A facility for getting the current method's name
neugens.limasoftware@gmail.com
neugens.limasoftware at gmail.com
Sun Sep 25 23:57:00 PDT 2011
Hi!
While it could be useful in very specific contexts, I actually think this is not really needed, since like you noted you get the same result creating a stacktrace and I doubt this would be anything but marginally faster, which would be overkill to require an api addition probably.
Cheers,
Mario
--
Sent from HTC Desire...
pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF
Fingerprint: BA39 9666 94EC 8B73 27FA FC7C 4086 63E3 80F2 40CF
http://www.icedrobot.org
Proud GNU Classpath developer: http://www.classpath.org/
Read About us at: http://planet.classpath.org
OpenJDK: http://openjdk.java.net/projects/caciocavallo/
Please, support open standards:
http://endsoftpatents.org/
----- Reply message -----
Da: "Behrang Saeedzadeh" <behrangsa at gmail.com>
Data: lun, set 26, 2011 04:51
Oggetto: A facility for getting the current method's name
A: <jdk8-dev at openjdk.java.net>
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