@Test public void testInstantiate() { assertThat(Classes.instantiate(NoArg.class), is(instanceOf(NoArg.class))); }
public static <T> T instantiate(Class<T> clazz) { try { return clazz .getConstructor() .newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException( String.format("Cannot instantiate %s", clazz.getName()), e); } }
Classes { public static <T> T instantiate(Class<T> clazz) { try { return clazz .getConstructor() .newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException( String.format("Cannot instantiate %s", clazz.getName()), e); } } }
Classes { public static <T> T instantiate(Class<T> clazz) { try { return clazz .getConstructor() .newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException( String.format("Cannot instantiate %s", clazz.getName()), e); } } private  Classes(); }
Classes { public static <T> T instantiate(Class<T> clazz) { try { return clazz .getConstructor() .newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException( String.format("Cannot instantiate %s", clazz.getName()), e); } } private  Classes(); static T instantiate(Class<T> clazz); }
Classes { public static <T> T instantiate(Class<T> clazz) { try { return clazz .getConstructor() .newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException( String.format("Cannot instantiate %s", clazz.getName()), e); } } private  Classes(); static T instantiate(Class<T> clazz);  }