Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Hello. I have a question on java type safety.
I have a method that accepts a class literal and (for sake of argument) returns an instance of any class (in fact there is slightly more to it).
Example:
Circle c = (Circle)this.returnInstance(Circle.class);
//removed exception handling
private Object returnInstance(Class c) throws Exception {
return c.newInstance();
}
My question is - is there any way to avoid performing the CAST (here, on the Circle instance) in the calling code?
Many thanks,
B