@Test void shouldReturnNullForNonGenericClass() { Class<?> mainType = Exception.class; Type genericType = mock(ParameterizedType.class); Class<?> result = ReflectionUtils.getCollectionType(mainType, genericType); assertThat(result, nullValue()); verifyNoInteractions(genericType); }
@Nullable public static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType) { if (mainType.isArray()) { return mainType.getComponentType(); } else if (Iterable.class.isAssignableFrom(mainType)) { return getGenericType(genericType); } return null; }
ReflectionUtils { @Nullable public static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType) { if (mainType.isArray()) { return mainType.getComponentType(); } else if (Iterable.class.isAssignableFrom(mainType)) { return getGenericType(genericType); } return null; } }
ReflectionUtils { @Nullable public static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType) { if (mainType.isArray()) { return mainType.getComponentType(); } else if (Iterable.class.isAssignableFrom(mainType)) { return getGenericType(genericType); } return null; } private  ReflectionUtils(); }
ReflectionUtils { @Nullable public static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType) { if (mainType.isArray()) { return mainType.getComponentType(); } else if (Iterable.class.isAssignableFrom(mainType)) { return getGenericType(genericType); } return null; } private  ReflectionUtils(); static Object getFieldValue(Field field, Object instance); static void setField(Field field, Object instance, Object value); static Object invokeMethod(Method method, Object instance, Object... parameters); static T newInstance(Constructor<T> constructor, Object... parameters); @Nullable static Class<?> getGenericType(@Nullable Type genericType); @Nullable static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType); static Object toSuitableCollectionType(Class<?> rawType, Set<T> result); static Method[] safeGetDeclaredMethods(Class<?> clazz); static Field[] safeGetDeclaredFields(Class<?> clazz); }
ReflectionUtils { @Nullable public static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType) { if (mainType.isArray()) { return mainType.getComponentType(); } else if (Iterable.class.isAssignableFrom(mainType)) { return getGenericType(genericType); } return null; } private  ReflectionUtils(); static Object getFieldValue(Field field, Object instance); static void setField(Field field, Object instance, Object value); static Object invokeMethod(Method method, Object instance, Object... parameters); static T newInstance(Constructor<T> constructor, Object... parameters); @Nullable static Class<?> getGenericType(@Nullable Type genericType); @Nullable static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType); static Object toSuitableCollectionType(Class<?> rawType, Set<T> result); static Method[] safeGetDeclaredMethods(Class<?> clazz); static Field[] safeGetDeclaredFields(Class<?> clazz);  }