I've have situation where the class which implements an interface need to be picked dynamically from a table. The absolute path of this class will be configured in the table. The class name will be picked from the table and then an instance of that class is created and executed using reflection API.
I'm assuming that there will be many instances created which may eat a lot of memory and also may have a performance impact. Am I right in this assumption? Is there any way to deal with my situation here?
Following is the code snippet:
Class<?> c = Class.forName(dynamicClass);
ServiceValidatorInterface inst = (ServiceValidatorInterface) c.newInstance();
inst.validateService(serviceDetails);
Aucun commentaire:
Enregistrer un commentaire