@Test public void testNewInstance() throws Exception{ SystemManagerImpl sysManager = (SystemManagerImpl)ReflectionUtils.newInstance(SystemManagerImpl.class, new Object[0]); Assert.assertNotNull(sysManager); MyClass mc = (MyClass)ReflectionUtils.newInstance(MyClass.class, new Object[]{"4",5}); Assert.assertEquals("4",ReflectionUtils.getField("str", MyClass.class).get(mc)); Assert.assertEquals(5,ReflectionUtils.getField("i", MyClass.class).get(mc)); }
public static Object newInstance(Class<? extends Object> cl,Object[] args) throws Exception { Class<? extends Object>[] classArray = new Class<?>[args == null ? 0 :args.length]; for (int i = 0 ; i < args.length;i++){ classArray[i] = builtInMap.get(args[i].getClass()) == null ? args[i].getClass(): builtInMap.get(args[i].getClass()); } Constructor<? extends Object> constructor = cl.getDeclaredConstructor(classArray); constructor.setAccessible(true); return constructor.newInstance(args); }
ReflectionUtils { public static Object newInstance(Class<? extends Object> cl,Object[] args) throws Exception { Class<? extends Object>[] classArray = new Class<?>[args == null ? 0 :args.length]; for (int i = 0 ; i < args.length;i++){ classArray[i] = builtInMap.get(args[i].getClass()) == null ? args[i].getClass(): builtInMap.get(args[i].getClass()); } Constructor<? extends Object> constructor = cl.getDeclaredConstructor(classArray); constructor.setAccessible(true); return constructor.newInstance(args); } }
ReflectionUtils { public static Object newInstance(Class<? extends Object> cl,Object[] args) throws Exception { Class<? extends Object>[] classArray = new Class<?>[args == null ? 0 :args.length]; for (int i = 0 ; i < args.length;i++){ classArray[i] = builtInMap.get(args[i].getClass()) == null ? args[i].getClass(): builtInMap.get(args[i].getClass()); } Constructor<? extends Object> constructor = cl.getDeclaredConstructor(classArray); constructor.setAccessible(true); return constructor.newInstance(args); }  }
ReflectionUtils { public static Object newInstance(Class<? extends Object> cl,Object[] args) throws Exception { Class<? extends Object>[] classArray = new Class<?>[args == null ? 0 :args.length]; for (int i = 0 ; i < args.length;i++){ classArray[i] = builtInMap.get(args[i].getClass()) == null ? args[i].getClass(): builtInMap.get(args[i].getClass()); } Constructor<? extends Object> constructor = cl.getDeclaredConstructor(classArray); constructor.setAccessible(true); return constructor.newInstance(args); }  static Field getField(String field,Class<?> cl); static Object newInstance(Class<? extends Object> cl,Object[] args); }
ReflectionUtils { public static Object newInstance(Class<? extends Object> cl,Object[] args) throws Exception { Class<? extends Object>[] classArray = new Class<?>[args == null ? 0 :args.length]; for (int i = 0 ; i < args.length;i++){ classArray[i] = builtInMap.get(args[i].getClass()) == null ? args[i].getClass(): builtInMap.get(args[i].getClass()); } Constructor<? extends Object> constructor = cl.getDeclaredConstructor(classArray); constructor.setAccessible(true); return constructor.newInstance(args); }  static Field getField(String field,Class<?> cl); static Object newInstance(Class<? extends Object> cl,Object[] args);  }