I want to return an instance of an object of same type of the Class object passed in. The type passed in can be ANYTHING. Is there a way to do this with Generics?
To
public C getObject(Class c) throws Exception
{
return c.newInstance();
}
Usage Example:
static C getObject(Class c) throws Exception {
return c.newInstance();
}
static class Testing {
{System.out.println("Instantiated");}
void identify(){ System.out.println("Invoked"); }
}
public static void main(String args[]) throws Exception {
Testing t = getObject(Testing.class);
t.identify();
}