Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

newInstance(), how to call a constructor and pass parameters to it?

843798Feb 17 2003 — edited Feb 20 2003
Hey all,

I am loading some classes dynamically. They all extend a specific "abstract" class that has a constructor with a number of parameters. I would like to be able to call this constructor and pass it the parameters dynamically. How is this done? I have seen the Method stuff, reflection, etc. But my code currently does something like:

MyClass mo = (MyClass)Class.forName(...).newInstance();

The MyClass may extend the "abstract" class I am talking about. In that abstract class the constructor takes on 3 parameters. So how could I call this at runtime to pass the 3 parameters?

Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 20 2003
Added on Feb 17 2003
1 comment
753 views