ReflectionUtils { @Api(2.0) @Nullable public static Class<?> toClass(@Nullable String name) { if (!TextUtils.isEmpty(name)) { try { return Class.forName(classNameToInnerFilter(name.trim())); } catch (ClassNotFoundException ignored) { } } return null; } private  ReflectionUtils(); @Api(2.0) @Nullable static Class<?> toClass(@Nullable String name); @Api(2.0) @Nullable static T newInstance(@NonNull Class<T> clazz); @Api(2.0) @NonNull static Constructor<T> getConstructor(@NonNull Class<T> constructedClass, @NonNull Class<D> innerConstructorClass); @Api(2.0) @NonNull static T build(@NonNull Constructor<T> constructor, @Nullable Object... data); @Api(2.0) @NonNull static String classNameToInnerFilter(@NonNull String className); @Api(2.0) @NonNull static Field[] getFields(@NonNull Class clazz, boolean bringParents); @Api(2.0) @NonNull static T valueOf(Field field, Object reference, Class<T> clazz);  }
@Test public void toClassTest() { Class clazz = ReflectionUtils.toClass("failed.Class"); Assert.assertEquals(null, clazz); clazz = ReflectionUtils.toClass(getClass().getCanonicalName()); Assert.assertEquals(getClass(), clazz); clazz = ReflectionUtils.toClass(null); Assert.assertEquals(null, clazz); }