File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Class.forName" Watch "Class.forName" New topic


S.Subhash Chandran

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="" target="_blank" rel="nofollow"></a>
karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
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)
[ May 26, 2003: Message edited by: karl koch ]
I agree. Here's the link:
subject: Class.forName
It's not a secret anymore!