This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Class.forName
jQuery in Action, 3rd edition