The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

CLASSNAME

Posted by IAIN on August 07, 2000 at 9:44 AM

here's an example:

private static String testMethod() {
String output = this.getClass().getName();
return output;
}

and this method should return the name of the class as a String.
I can't just type in the classname because its prone to be changed alot, and we don't want to find every place the name is written and change it, so I need this little bit of code to return whatever the class name currently happens to be.
Unfortunately, 'this' cannot be referenced from a static context, and so this method will not compile. So if you know an alternative to this.getClass().getName() that will return the classname as a string, let me know! Thanx.






Replies:
  • ClassName Mahesh August 29, 2000 at 9:19 PM (0)

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us