dcsimg
How can I get the application class name?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kyle_Mallory
Posted On:   Tuesday, July 30, 2002 03:43 PM

I am developing a component package, and I want the package to know the class name of the implimenting class (the application). Is this possible?



For example, class A imports and instantiates class B, I want class B to get "A" from class A without passing class A as an argument. Ideally, I want to know the class name that impliments main() (or other entry points for applets, servlets, etc).



I've looked into everything from Threads to printStackTrace, etc. There are a few solutions (namely printStackTrace, parsing for main()), but there has got to be a better way...



Kyle

Re: How can I get the application class name?

Posted By:   Animesh_Srivastava  
Posted On:   Wednesday, July 31, 2002 12:45 AM

Use the Reflection API. Coupled with java.lang.Class it provides a useful way to retrieve class information at runtime. There are few things like getName, getClass, getSuperClass etc, which you may find useful for getting class information.

For a good tutorial on reflection you may like to check out http://java.sun.com/docs/books/tutorial/reflect/


Hope that helps

Animesh.

About | Sitemap | Contact