fatcodeguy
Programmer
Hi,
I'm wondering if this is at all possible. Based on an input, a String named after a Class, I want to instantiate an object as that class. All objects are subclasses of an abstract class I defined, which extends Threads.
So now I do the following
and so on. The problem with this is that if I want to add new implementations, I have to modify the classes that call this type of code, instead of changing a config file that has the classname I want to use.
I'd like to see something like this
I'm hoping that java has something like this. Doe this make sense? Is this at all possible, or am I just being stupid?
All help greatly appreciated!! Thanks!!
I'm wondering if this is at all possible. Based on an input, a String named after a Class, I want to instantiate an object as that class. All objects are subclasses of an abstract class I defined, which extends Threads.
So now I do the following
Code:
Thread myThread = null;
if (input==myThread1Name)
myThread = new MyThread1();
else if (input==myThread2Name)
myThread = new MyThread2();
...
...
and so on. The problem with this is that if I want to add new implementations, I have to modify the classes that call this type of code, instead of changing a config file that has the classname I want to use.
I'd like to see something like this
Code:
myThread = SomeJavaFunction(inputclassname);
I'm hoping that java has something like this. Doe this make sense? Is this at all possible, or am I just being stupid?
All help greatly appreciated!! Thanks!!