<!--hutool-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.0.6</version>
</dependency>
/**
* @Author: Fcx
* @Date: 2019/11/20 20:45
* @Version 1.0
*/
public class CopyListUtil {
private CopyListUtil() {
}
/**
* 列表对象拷贝
* @param sources 源列表
* @param clazz 目标列表对象Class
* @param <T> 目标列表对象类型
* @param <M> 源列表对象类型
* @return 目标列表
*/
public static <T, M> List<T> copyListProperties(List<M> sources, Class<T> clazz) {
if (Objects.isNull(sources) || Objects.isNull(clazz) || sources.isEmpty()) {
throw new IllegalArgumentException();
}
List<T> targets = new ArrayList<>(sources.size());
for (M source : sources) {
T t = ReflectUtil.newInstance(clazz);
BeanUtil.copyProperties(source,t);
targets.add(t);
}
return targets;
}
}
标签:java,List,param,列表,sources,copyProperties,clazz,targets
From: https://blog.51cto.com/u_16110904/7326156