Re: WhoAmI

Suresh Babu Koya <[email protected]>
Newsgroups gmane.comp.java.sun.servlet
Message-ID <[email protected]>
Why not MyObject.class.getName()? Atleast you need not create
any object.

> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[email protected]]On Behalf Of Mr.
> Cristian D. Romanescu
> Sent: Friday, July 16, 2004 3:00 PM
> To: [email protected]
> Subject: Re: WhoAmI
>
>
> In my oppinion is a very bad software design to use Exceptions for
> normal operation...such as this.
>
> I would go for new MyObject().getClass().getName();
>
> [email protected] wrote:
>
> > tnx a lot for the insight!
> > You solved me a refactoring problem in a project with 3000 classes
> > Only that I'm using the JDK 1.3.2, so I have a bit of more work
> than this.
> >
> > package unknown;
> >
> > import java.io.StringWriter;
> > import java.io.PrintWriter;
> >
> > class WhoAmI{
> >         private static String className;
> >         static{
> >                 StringWriter stackTrace = new StringWriter();
> >                 new Exception().printStackTrace( new
> PrintWriter( stackTrace));
> >                 className = stackTrace.toString();
> >                 className = className.substring(
> className.indexOf("at ") + "at ".length());
> >                 className = className.substring( 0,
> className.indexOf(".<clinit>"));
> >         }
> > }
> >
> >
> >
> >>[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
> >>
> >
> >
> >
> __________________________________________________________________
> _________
> > 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
>
> __________________________________________________________________
> _________
> 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
>

___________________________________________________________________________
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.