aspose file tools*
The moose likes Java in General and the fly likes Class.forName Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Class.forName" Watch "Class.forName" New topic
Author

Class.forName

S.Subhash Chandran
Greenhorn

Joined: Dec 31, 2002
Posts: 27
I am creating an instance of a new class dynamically:
Object obj = Class.forName(classNme).newInstance();
The problem is that, how do I pass values to the constructor of ``classNme''?


Subhash Chandran S<br /><a href="http://www.indiwiz.com/" target="_blank" rel="nofollow">http://www.indiwiz.com/</a>
karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
hi
from the Class object you can get the desired Constructor using:

and then create a new instance using:

check also the java.lang.reflect API description (online api)
k
[ May 26, 2003: Message edited by: karl koch ]
 
Don't get me started about those stupid light bulbs.
 
subject: Class.forName