@Test public void testNewInstance_classUnmatch() throws Exception { String baseName = getClass().getName(); try { ReflectUtil.newInstance(Aaa.class, baseName + "$Ccc"); fail(); } catch (ClassUnmatchRuntimeException expected) { } }
public static <T> T newInstance(Class<T> expectedClass, String className) { Class<?> actualClass = ClassUtil.forName(className); Object obj = ClassUtil.newInstance(actualClass); if (expectedClass.isInstance(obj)) { return expectedClass.cast(obj); } throw new ClassUnmatchRuntimeException(expectedClass, actualClass); }
ReflectUtil { public static <T> T newInstance(Class<T> expectedClass, String className) { Class<?> actualClass = ClassUtil.forName(className); Object obj = ClassUtil.newInstance(actualClass); if (expectedClass.isInstance(obj)) { return expectedClass.cast(obj); } throw new ClassUnmatchRuntimeException(expectedClass, actualClass); } }
ReflectUtil { public static <T> T newInstance(Class<T> expectedClass, String className) { Class<?> actualClass = ClassUtil.forName(className); Object obj = ClassUtil.newInstance(actualClass); if (expectedClass.isInstance(obj)) { return expectedClass.cast(obj); } throw new ClassUnmatchRuntimeException(expectedClass, actualClass); } protected  ReflectUtil(); }
ReflectUtil { public static <T> T newInstance(Class<T> expectedClass, String className) { Class<?> actualClass = ClassUtil.forName(className); Object obj = ClassUtil.newInstance(actualClass); if (expectedClass.isInstance(obj)) { return expectedClass.cast(obj); } throw new ClassUnmatchRuntimeException(expectedClass, actualClass); } protected  ReflectUtil(); static T newInstance(Class<T> expectedClass, String className); }
ReflectUtil { public static <T> T newInstance(Class<T> expectedClass, String className) { Class<?> actualClass = ClassUtil.forName(className); Object obj = ClassUtil.newInstance(actualClass); if (expectedClass.isInstance(obj)) { return expectedClass.cast(obj); } throw new ClassUnmatchRuntimeException(expectedClass, actualClass); } protected  ReflectUtil(); static T newInstance(Class<T> expectedClass, String className);  }