Hi
I have a class which has a static method that takes a
String classname and returns the instance of type class. My method looks like:
public static <T extends Object> T getClassInstance(String className) throws Exception{
T instanceToReturn = null;
try {
Class c = Class.forName(className);
instanceToReturn = (T)c.newInstance();
} catch (InstantiationException e) {
throw e;
} catch (IllegalAccessException e) {
throw e;
} catch (ClassNotFoundException e) {
throw e;
}
return instanceToReturn;
}
I get the following warning:
Type safety: The cast from Object to T is actually checking against the erased type Object. Should I be worried about this warning? How can I avoid it?
I am very new to Generics, so am not sure if this is the correct way to use it. Any help would be great.
Thanks
Aanal