@Test public void getConstructorTest() throws Exception { Object[] args1 = {new A(), new B(), 10}; Object[] args2 = {new B(), 10}; Constructor<C> ctr1 = Reflection.getConstructor(C.class, args1); Constructor<C> ctr2 = Reflection.getConstructor(C.class, args2); Assert.assertNotNull(ctr1); Assert.assertNotNull(ctr2); Assert.assertEquals(1, ctr1.newInstance(args1).ctrId); Assert.assertEquals(2, ctr2.newInstance(args2).ctrId); }
public static <T> Constructor<T> getConstructor(Class<T> clazz, Object... args) throws NoSuchMethodException { Class<?>[] argCls = new Class[args.length]; for (int i = 0; i < args.length; i++) { argCls[i] = args[i].getClass(); } return getConstructor(clazz, argCls); }
Reflection { public static <T> Constructor<T> getConstructor(Class<T> clazz, Object... args) throws NoSuchMethodException { Class<?>[] argCls = new Class[args.length]; for (int i = 0; i < args.length; i++) { argCls[i] = args[i].getClass(); } return getConstructor(clazz, argCls); } }
Reflection { public static <T> Constructor<T> getConstructor(Class<T> clazz, Object... args) throws NoSuchMethodException { Class<?>[] argCls = new Class[args.length]; for (int i = 0; i < args.length; i++) { argCls[i] = args[i].getClass(); } return getConstructor(clazz, argCls); }  }
Reflection { public static <T> Constructor<T> getConstructor(Class<T> clazz, Object... args) throws NoSuchMethodException { Class<?>[] argCls = new Class[args.length]; for (int i = 0; i < args.length; i++) { argCls[i] = args[i].getClass(); } return getConstructor(clazz, argCls); }  static Constructor<T> getConstructor(Class<T> clazz, Object... args); static Constructor<T> getConstructor(Class<T> clazz, Class<?>... args); }
Reflection { public static <T> Constructor<T> getConstructor(Class<T> clazz, Object... args) throws NoSuchMethodException { Class<?>[] argCls = new Class[args.length]; for (int i = 0; i < args.length; i++) { argCls[i] = args[i].getClass(); } return getConstructor(clazz, argCls); }  static Constructor<T> getConstructor(Class<T> clazz, Object... args); static Constructor<T> getConstructor(Class<T> clazz, Class<?>... args);  }