I want to write a method just like spring's bean instantiation method.
context.getBean("beanobjectname", Type);
I have multiple interfaces which will be implemented by developers and developers will put the class name in a property file from where I will read the class name in the form of string just like in bean.xml . I want to write a generic method to instantiate the object of class implementing these interfaces by just passing the classname in the form of string and the type where i will pass type of interface. Please help.
EDIT 1
Expecting the content of method like the following. But this is showing compile errors.
public <T> T getObject(String className, Class<T> type) throw ClassNotFoundException{
Class<?> clazz = Class.forName(className);
T object = (T)clazz.newInstance();
if(clazz instanceof type){
return (type)clazz;
}
return null;
}