Hello,
My program needs to create a class, see code below to understand ;-)
/**
* Loads system's class and execute it
*/
private static void loadSystem(String systemName,String symbol) {
// wrong code:
systemName system = new systemName(symbol);
}
the first param is systemName, the name of the class to create.
I cannot create it such as "systemName system = new sytemName(symbol)"
because systemName is a String and not a Class.
How can I solve this problem?
If something is not clear please ask, I will explain better :-)
thank you
Dale King - 01 Jul 2005 15:25 GMT
> Hello,
>
[quoted text clipped - 15 lines]
>
> How can I solve this problem?
Check out the java.lang.Class class. Specifically the forName static
method. To create a newInstance you can use the newInstance method, but
that only works for the no-arg constructor. To actually pass args you
have to use getConstructor to get the correct constructor which you can
then call newInstance on passing the args.

Signature
Dale King