Say I have a class called ModelX, but my program doesn't know about this class untill runtime.
So to create it I can't do:
private ModelX aModel;
Because it doesn't know its name or its existance yet, the only thing it does do is read its name from say a simple .txt file.
How can I make it load the class from a string and then get its constructor, so that I can do
String x = "ModelX";
cls = Class.forName("x");
Object obj = cls.newInstance();
for example, so that I can do
aModel = new obj();
and
private obj aModel;
I'm sorry if the description is vague but I do not really know how to describe what I want.
I need to be able to do this:
aModel = new ModelX();
private ModelX aModel;
While I got ModelX from a string.