I want to create a method that constructs an object of a class received as a parameter much like the following one:
public static <T extends MyAbstractClass> T makeObject(Class<T> c){
ObjectReceivedFromService orfs = getObjectFromService();
Constructor<T> constr = c.getConstructor(ObjectReceivedFromService.class);
return constr.newInstance(orfs);
}
Is there a way to make sure that this specific constructor exists on compile time? I would also like to use an interface instead of an abstract class if possible.
Thank you