add null check

This commit is contained in:
Looly 2021-08-10 21:38:34 +08:00
parent e89ca1ace3
commit b286f3743d

View File

@ -23,6 +23,7 @@ import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
@ -724,6 +725,12 @@ public class BeanUtil {
* @since 5.6.4
*/
public static <T> List<T> copyToList(Collection<?> collection, Class<T> targetType, CopyOptions copyOptions){
if(null == collection){
return null;
}
if(collection.isEmpty()){
return new ArrayList<>(0);
}
return collection.stream().map((source)->{
final T target = ReflectUtil.newInstanceIfPossible(targetType);
copyProperties(source, target, copyOptions);