Some of the solutions offered are creative, but don't actually do
anything very useful. A static method or variable belongs to the class
it is part of and has no membership in subclasses. By definition, the
editor of the static WhoAmI() method has to know the name of the class.
As one of the replies to this thread indicated you can get the Class
object itself with the XYZ.class mechanism which does the same thing as
Class.forName("XYZ") without having to catch ClassNotFoundException .
Date: Thu, 15 Jul 2004 13:46:59 +0200
From: Michael Weller <[EMAIL PROTECTED]>
Subject: Re: WhoAmI
[EMAIL PROTECTED] wrote:
How can a class discover in a static context what fully qualified name is its own?
package unknown;
class WhoAmI{
private static final className = ...????;
}
I can't use, of course, this.getClass().getName().
What about 'String myName = new
Exception().getStackTrace()[0].getClassName();'?
-mw
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html