Java泛型List clone

2014-11-24 07:56:13 · 作者: · 浏览: 0

public static List copy(List source) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
//clone后的集合
List temp=new ArrayList();

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;
}

public static List copy(List source) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
//clone后的集合
List temp=new ArrayList();

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;
}

摘自 yhc13429826359的专栏