I have a Class object, clazz. I want to make the object of that type class.
i.e. Class clazz = MTable.getClass(tableName);
The variable clazz may be of type MOrder.class, MInventory.class, or MSalary.class.
Now I want to make the object of MOrder for an instance.
Without comparing the clazz with MOrder.class, how can I create object of MOrder.
Is Java providing any such mechanism?
Update:
I tried this:
Class<? extends DocAction> clazz = (Class<? extends DocAction>) MTable.getClass(re.tableName);
DocAction instance = null;
try {
instance = clazz.newInstance();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
But an exception is thrown:
java.lang.InstantiationException: org.compiere.model.MOrder
MInventory.classorMSalary.class? Why not instantiateMOrderdirectly?