File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Android Security Essentials Live Lessons
this week in the
Java in General
Joined: Dec 31, 2002
May 26, 2003 02:58:00
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>
Joined: May 25, 2001
May 26, 2003 03:41:00
from the Class object you can get the desired Constructor using:
Class clazz = .....; Class paramTypes = .....; Constructor const = clazz.getConstructor(paramTypes);
and then create a new instance using:
Object initargs = ....; MyObject newObj =(MyObject) const.newInstance(initArgs);
check also the java.lang.reflect API description (
[ May 26, 2003: Message edited by: karl koch ]
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
Dynamically loading a class
Using jdbc from jsp with MySQL
what this method do in JDBC?
Exporting Myclass.class bindings to an external file.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014