Posted By:
Prasad_P
Posted On:
Friday, May 30, 2003 05:49 AM
How can i pass a run time object as a constructor parameter of a runtime object ? consider the below sequence HashMap actions = new HashMap(); HashMap models = new HashMap(); actions.put("TestOp","Testing"); // here TestOp is the key and Testing is Class Name. models.put("TestOp","TestingPart"); // here TestOp is the key and TestingPart is Class Name.and //Testing part extends Test which is an abstract class. Object objValue = actions.get("TestOp"); Object objValue1 = models.get("TestOp"); try { // I would like to create a statement below l
More>>
How can i pass a run time object as a constructor parameter of a runtime
object ?
consider the below sequence
HashMap actions = new HashMap();
HashMap models = new HashMap();
actions.put("TestOp","Testing");
// here TestOp is the key and Testing is Class Name.
models.put("TestOp","TestingPart");
// here TestOp is the key and TestingPart is Class Name.and
//Testing part extends Test which is an abstract class.
Object objValue = actions.get("TestOp");
Object objValue1 = models.get("TestOp");
try
{
// I would like to create a statement below like
// Test testObj = new Testing(new (TestingPart))
how can i do this ?
I presume doing
Test testObj = (Test)getClass().getClassLoader().loadClass(objValue.toString()).newInstance();
// will create an object of Testing but how can i pass an object of TestingPart ?
testObj.perform();
}
catch(Exception e)
{
e.printStackTrace();
}
Please help me with suggestions. Thanks in advance for any reply.
<<Less