goback add

Java泛型List clone

3431 点击·0 回帖
灯火互联
楼主


public static <T> List<T> copy(List<T> source) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException  {
    //clone后的集合  
    List<T> temp=new ArrayList<T>();
    
    for(T tource){
        
        //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 <T> List<T> copy(List<T> source) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException  {
     //clone后的集合
     List<T> temp=new ArrayList<T>();
    
     for(T tource){
      
       //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;
    }



喜欢0 评分0