import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException;
publicfinalclass GenericInstantiator { public <T> T makeInstance(Class<T> c) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException { T instance = null ; Class[] emptyParams = {}; Constructor<T> con = c.getDeclaredConstructor(emptyParams); con.setAccessible( true ); instance = con.newInstance(); return instance; } }
Class<T> c
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question