ClassUtils { public static Object newInstance(String name) { try { return forName(name).newInstance(); } catch (InstantiationException e) { throw new IllegalStateException(e.getMessage(), e); } catch (IllegalAccessException e) { throw new IllegalStateException(e.getMessage(), e); } } private  ClassUtils(); static Object newInstance(String name); static Class<?> forName(String[] packages, String className); static Class<?> forName(String className); static Class<?> classForName(String className); static Class<?> getBoxedClass(Class<?> type); static Boolean boxed(boolean v); static Character boxed(char v); static Byte boxed(byte v); static Short boxed(short v); static Integer boxed(int v); static Long boxed(long v); static Float boxed(float v); static Double boxed(double v); static Object boxed(Object v); static boolean unboxed(Boolean v); static char unboxed(Character v); static byte unboxed(Byte v); static short unboxed(Short v); static int unboxed(Integer v); static long unboxed(Long v); static float unboxed(Float v); static double unboxed(Double v); static Object unboxed(Object v); static boolean isNotEmpty(Object object); static int getSize(Object object); static URI toURI(String name); static Class<?> getGenericClass(Class<?> cls); static Class<?> getGenericClass(Class<?> cls, int i); static boolean isBeforeJava5(String javaVersion); static boolean isBeforeJava6(String javaVersion); static String toString(Throwable e); static void checkBytecode(String name, byte[] bytecode); static String getSizeMethod(Class<?> cls); static String getMethodName(Method method, Class<?>[] parameterClasses, String rightCode); static Method searchMethod(Class<?> currentClass, String name, Class<?>[] parameterTypes); static String getInitCode(Class<?> type); static Map<K, V> toMap(Map.Entry<K, V>[] entries); static String getSimpleClassName(String qualifiedName); static final String CLASS_EXTENSION; static final String JAVA_EXTENSION; }
@Test public void testNewInstance() { HelloServiceImpl0 instance = (HelloServiceImpl0) ClassUtils.newInstance(HelloServiceImpl0.class.getName()); Assertions.assertEquals("Hello world!", instance.sayHello()); }
@Test public void testNewInstance0() { Assertions.assertThrows(IllegalStateException.class, () -> ClassUtils.newInstance(PrivateHelloServiceImpl.class.getName())); }
@Test public void testNewInstance1() { Assertions.assertThrows(IllegalStateException.class, () -> ClassUtils.newInstance("org.apache.dubbo.common.compiler.support.internal.HelloServiceInternalImpl")); }
@Test public void testNewInstance2() { Assertions.assertThrows(IllegalStateException.class, () -> ClassUtils.newInstance("org.apache.dubbo.common.compiler.support.internal.NotExistsImpl")); }