/**
* 转换list类型
* @param oldList 被复制的list
* @param clazz 新list的元素类型
* @return newList 复制完成的的集合
*/
public static <T> List<T> copyList(List<?> oldList, Class<T> clazz){
//判断被复制的list是否为空
if (oldList == null){
return new ArrayList<>( 0 );
}
//初始化新list
List<T> newList = new ArrayList<>( );
oldList.forEach( o -> {
try {
T o1 = clazz.newInstance();
BeanUtils.copyProperties( o,o1 );
newList.add( o1 );
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
} );
return newList;
}
转载于:https://my.oschina.net/u/2555967/blog/3041369