@Test @SuppressWarnings("ConstantConditions") public void newArrayFromCollectionReturnsNullWhenCollectionIsNull() { Object[] objects = ReflectionHelper.newArrayFromCollection(null, Integer.class); assertThat(objects).isNull(); }
public static <T> T[] newArrayFromCollection(final Collection<?> collection, final Class<T> elementType) { if (collection == null) { return null; } @SuppressWarnings({"unchecked"}) T[] array = (T[]) Array.newInstance(elementType, collection.size()); int i = 0; for (Object element : collection) { Array.set(array, i++, element); } return array; }
ReflectionHelper { public static <T> T[] newArrayFromCollection(final Collection<?> collection, final Class<T> elementType) { if (collection == null) { return null; } @SuppressWarnings({"unchecked"}) T[] array = (T[]) Array.newInstance(elementType, collection.size()); int i = 0; for (Object element : collection) { Array.set(array, i++, element); } return array; } }
ReflectionHelper { public static <T> T[] newArrayFromCollection(final Collection<?> collection, final Class<T> elementType) { if (collection == null) { return null; } @SuppressWarnings({"unchecked"}) T[] array = (T[]) Array.newInstance(elementType, collection.size()); int i = 0; for (Object element : collection) { Array.set(array, i++, element); } return array; } private  ReflectionHelper(); }
ReflectionHelper { public static <T> T[] newArrayFromCollection(final Collection<?> collection, final Class<T> elementType) { if (collection == null) { return null; } @SuppressWarnings({"unchecked"}) T[] array = (T[]) Array.newInstance(elementType, collection.size()); int i = 0; for (Object element : collection) { Array.set(array, i++, element); } return array; } private  ReflectionHelper(); static Class<?> getClassForName(final String className); static Class<?> getArrayType(final Class<?> type); static Field getDeclaredField(final Object bean, final String fieldName); static Object getFieldValue(final Object bean, final String fieldName); static Class<?> getGenericType(final Field field); static T newCollectionInstance(final Class<T> clazz); static T newInstance(final Class<T> clazz); static T newInstance(final String fullyQualifiedClassName, final Class<T> superType); static List<T> createInstances(final List<String> fullyQualifiedClassNames, final Class<T> superType); static void setFieldValue(final Object bean, final String fieldName, final Object value); static Set<Field> getDeclaredFieldsWithAnnotationRecursively(final Class<?> clazz,
                                                                        final Class<? extends Annotation> annotationClass); static T[] newArrayFromCollection(final Collection<?> collection, final Class<T> elementType); }
ReflectionHelper { public static <T> T[] newArrayFromCollection(final Collection<?> collection, final Class<T> elementType) { if (collection == null) { return null; } @SuppressWarnings({"unchecked"}) T[] array = (T[]) Array.newInstance(elementType, collection.size()); int i = 0; for (Object element : collection) { Array.set(array, i++, element); } return array; } private  ReflectionHelper(); static Class<?> getClassForName(final String className); static Class<?> getArrayType(final Class<?> type); static Field getDeclaredField(final Object bean, final String fieldName); static Object getFieldValue(final Object bean, final String fieldName); static Class<?> getGenericType(final Field field); static T newCollectionInstance(final Class<T> clazz); static T newInstance(final Class<T> clazz); static T newInstance(final String fullyQualifiedClassName, final Class<T> superType); static List<T> createInstances(final List<String> fullyQualifiedClassNames, final Class<T> superType); static void setFieldValue(final Object bean, final String fieldName, final Object value); static Set<Field> getDeclaredFieldsWithAnnotationRecursively(final Class<?> clazz,
                                                                        final Class<? extends Annotation> annotationClass); static T[] newArrayFromCollection(final Collection<?> collection, final Class<T> elementType);  }