ReflectionHelper { public static <T> T instantiate(final Class<? extends T> type, final Object... params) { try { final Constructor<T> constructor = findCompatibleConstructor(type, params); constructor.setAccessible(true); return constructor.newInstance(params); } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } }  static T instantiate(final Class<? extends T> type, final Object... params); static Object invokeMethod(final Object targetObject,
                                      final String methodName,
                                      final Object... params); static boolean argumentTypesCompatible(final Executable executable,
                                                  final Object[] prms); static boolean typeIsCompatible(final Object paramObject, final Class<?> type); static Class<?> wrapPrimitive(final Class<?> type);  }
@Test public void instantiateWithDefaultConstructor() { assertThat(instantiate(NotMuchHere.class), CoreMatchers.is(CoreMatchers.equalTo(new NotMuchHere()))); }
@Test public void instantiateWithParams() { assertThat(instantiate(TwoArgs.class, 123, "abc"), CoreMatchers.is(CoreMatchers.equalTo(new TwoArgs(123, "abc")))); }