百度一下啥也没有,先看看这个吧
java 根据泛型创建对象,实例化泛型对象_Sirius的博客-CSDN博客_泛型创建对象实例化泛型对象在你发布的代码中,不可能创建一个泛型T,因为你不知道它是什么类型:public class Abc
老实说我没看懂
换个思路,传入demo,或者class
public staticvoid toIPageVo(IPage foIPage, IPageVo iPageVo,T voDemo) throws InvocationTargetException, IllegalAccessException { List foList = foIPage.getRecords(); List toList = new ArrayList (); for (Object foRecord : foList) { T vo=null; try { vo = (T) voDemo.getClass().newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } BeanUtilImpl.copyToVo(vo,foRecord); toList.add(vo); } iPageVo.setRecords(toList); iPageVo.setCurrent(foIPage.getCurrent()); iPageVo.setSize(foIPage.getSize()); iPageVo.setTotal(foIPage.getTotal()); iPageVo.setPages(foIPage.getPages()); }
public staticvoid toIPageVo(IPage foIPage, IPageVo iPageVo,Class clazz) throws InvocationTargetException, IllegalAccessException { List foList = foIPage.getRecords(); List toList = new ArrayList (); for (Object foRecord : foList) { T vo=null; try { vo = (T) clazz.newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } BeanUtilImpl.copyToVo(vo,foRecord); toList.add(vo); } iPageVo.setRecords(toList); iPageVo.setCurrent(foIPage.getCurrent()); iPageVo.setSize(foIPage.getSize()); iPageVo.setTotal(foIPage.getTotal()); iPageVo.setPages(foIPage.getPages()); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)