@Test void newInstanceWithArg() { Constructor<ClassWithMultipleConstructors> constructor = ClassUtil.constructor(ClassWithMultipleConstructors.class, Integer.TYPE) .orElseThrow(() -> new AssertionError("Failed to get constructor from " + ClassWithMultipleConstructors.class)); ClassWithMultipleConstructors result = ConstructorUtil.newInstance(constructor, 123); assertThat(result, notNullValue()); assertThat(result.intValue(), is(123)); }
public static <T> T newInstance(Constructor<T> ctor, Object... args) { try { ctor.setAccessible(true); return ctor.newInstance(args); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } }
ConstructorUtil extends UtilityClass { public static <T> T newInstance(Constructor<T> ctor, Object... args) { try { ctor.setAccessible(true); return ctor.newInstance(args); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } }
ConstructorUtil extends UtilityClass { public static <T> T newInstance(Constructor<T> ctor, Object... args) { try { ctor.setAccessible(true); return ctor.newInstance(args); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } }  }
ConstructorUtil extends UtilityClass { public static <T> T newInstance(Constructor<T> ctor, Object... args) { try { ctor.setAccessible(true); return ctor.newInstance(args); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } }  static T newInstance(Constructor<T> ctor, Object... args); }
ConstructorUtil extends UtilityClass { public static <T> T newInstance(Constructor<T> ctor, Object... args) { try { ctor.setAccessible(true); return ctor.newInstance(args); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } }  static T newInstance(Constructor<T> ctor, Object... args);  }