hallo,
I have an abstract class and some classes that extends it.
I would like to be able to load an external class (that extends my abstract class) and use it in my program.
I defined a classLoader to look for and define the external class (saved in the filesystem as a .class file).
This procedure works fine, but then I have problems in creating an instance of the class.
code so far:
any ideas, examples? I guess I should use newInstance() method. But how? Thanks
I have an abstract class and some classes that extends it.
I would like to be able to load an external class (that extends my abstract class) and use it in my program.
I defined a classLoader to look for and define the external class (saved in the filesystem as a .class file).
This procedure works fine, but then I have problems in creating an instance of the class.
code so far:
Code:
import java.lang.reflect.*;
import java.lang.Exception.*;
public class MainClass
{
public static void main(String[] args)
{
myLoader loader = new myLoader();
try
{
Class newClass = loader.findClass("c:\\test\\test");
\\ to check if the class was loaded I print its methods (it works)
Method m[] = newClass.getDeclaredMethods();
for (int i = 0; i < m.length; i++)
{
System.out.println(m[i].toString());
}
// here I should instantate the class...
}
catch (ClassNotFoundException ex)
{
System.out.println(ex.toString());
}
}
}
any ideas, examples? I guess I should use newInstance() method. But how? Thanks