This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class.forName
 
Similar Threads
what this method do in JDBC?
Exporting Myclass.class bindings to an external file.
Dynamically loading a class
Using jdbc from jsp with MySQL
DriverManager.getConnection()