ClassUtils { public static Object instantiate(String className, Object ... args) { return instantiate(loadClass(className), args); } private  ClassUtils(); static Class<?> loadClass(String className); static Object instantiate(String className, Object ... args); static Object instantiate(Class klass, Object ... args); static String jarForClass(String className); static String jarForClass(Class klass); static String[] getEnumStrings(Class klass);  }
@Test public void testInstantiateNull() { assertNull(ClassUtils.instantiate((Class) null)); }
@Test public void testInstantiate() { A a = (A) ClassUtils.instantiate(A.class, "a"); assertNotNull(a); assertEquals(1, a.num); assertEquals("a", a.a); A b = (A) ClassUtils.instantiate(A.class, "b", 3, 5); assertNotNull(b); assertEquals(3, b.num); assertEquals("b", b.a); assertEquals(3, b.b); assertEquals(5, b.c); Primitive p = (Primitive) ClassUtils.instantiate(Primitive.class, 1, 1.0f, true); assertNotNull(p); assertEquals(1, p.i); assertEquals(1.0f, p.f, 0.0f); assertEquals(true, p.b); A c = (A) ClassUtils.instantiate(A.class, new Child()); assertNotNull(c); assertNotNull(c.p); assertEquals(Child.class, c.p.getClass()); }