mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add null check
This commit is contained in:
parent
e89ca1ace3
commit
b286f3743d
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user