M
munki
I have some code like this, which works fine:
ClassLoader myClassLoader = TestConstructors.class.getClassLoader();
try {
Class myClass =
myClassLoader.loadClass("net.munki.util.classloader.Module");
String arg = "HELLO";
Class[] parameters = new Class[] { arg.getClass() };
Constructor c = myClass.getConstructor(parameters);
Object o = c.newInstance(new Object[] { arg });
net.munki.util.classloader.Module m =
(net.munki.util.classloader.Module)o;
m.start();
}
catch ...
It instantiates a class passing "HELLO" to one of the constructors, and
executes a method on the resulting object. So far so good. However, I also
have a constructor that takes an int as a parameter. Since I can only pass
an Object[] to the newInstance() of a Constructor, how am I going to pass my
int in order to instantiate an object?
Thx
munki
ClassLoader myClassLoader = TestConstructors.class.getClassLoader();
try {
Class myClass =
myClassLoader.loadClass("net.munki.util.classloader.Module");
String arg = "HELLO";
Class[] parameters = new Class[] { arg.getClass() };
Constructor c = myClass.getConstructor(parameters);
Object o = c.newInstance(new Object[] { arg });
net.munki.util.classloader.Module m =
(net.munki.util.classloader.Module)o;
m.start();
}
catch ...
It instantiates a class passing "HELLO" to one of the constructors, and
executes a method on the resulting object. So far so good. However, I also
have a constructor that takes an int as a parameter. Since I can only pass
an Object[] to the newInstance() of a Constructor, how am I going to pass my
int in order to instantiate an object?
Thx
munki