public static <T> List<T> copy(List<T> source) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
//clone后的集合
List<T> temp=new ArrayList<T>();
for(T t:source){
//T temporary=(T) source.getClass().newInstance();
//BeanUtils.copyProperties(temporary,t);//Spring BeanUtils or Apache Commons
T temporary=(T) BeanUtils.cloneBean(t);
temp.add(temporary);
}
return temp;
}
Java 泛型List clone
最新推荐文章于 2024-08-25 22:33:50 发布
本文介绍了一种使用泛型复制列表元素的方法,通过创建一个公共静态方法来实现列表元素的复制,避免了直接调用类的实例方法带来的潜在问题。
55

被折叠的 条评论
为什么被折叠?



