CSDNRGY 2017-05-17 10:03 采纳率: 87.5%
浏览 1779
已采纳

为什么使用了List<T>,代码就无法编译?

如果不该成List
程序就会一直有警告
如何修改才是最符合规范的呢?

    public List<T> excelToList(String filePath, Class<T> cls) {
    //----------把这里的List<T>改成List-这段代码就可以正常执行了------------------------------
        List<T> result = new ArrayList<>();
        try {
            Workbook wb = new XSSFWorkbook(filePath);
            int sheetLength = wb.getNumberOfSheets();
            for (int i = 0; i < sheetLength; i++) {
                Sheet sheet = wb.getSheetAt(i);
                int rowLength = sheet.getPhysicalNumberOfRows();
                for (int j = 0; j < rowLength; j++) {
                    T t = cls.newInstance();
                    ComExcel comExcel = (ComExcel) t;
                    Row row = sheet.getRow(j);
                    int cellLength = row.getPhysicalNumberOfCells();
                    for (int k = 0; k < cellLength; k++) {
                        Cell cell = row.getCell(k);
                        String cellValue = cell.getStringCellValue();
                        Row title = sheet.getRow(0);
                        Cell titleCell = title.getCell(k);
                        String titleCellValue = titleCell.getStringCellValue();
                        Field[] fields = Emp.class.getDeclaredFields();
                        for (int l = 0; l < fields.length; l++) {
                            Field field = fields[l];
                            ExcelField ef = field.getDeclaredAnnotation(ExcelField.class);
                            String anTitle = ef.title();
                            if (titleCellValue.equals(anTitle)) {
                                Field[] declaredFields = Emp.class.getDeclaredFields();
                                for (Field f : declaredFields) {
                                    ExcelField declaredAnnotation = f.getDeclaredAnnotation(ExcelField.class);
                                    String extitle = declaredAnnotation.title();
                                    if (extitle.equals(titleCellValue)) {
                                        String fName = f.getName();
                                        fName = firstToUpper(fName);
                                        comExcel.getClass().getMethod("set" + fName, new Class[] { String.class })
                                                .invoke(comExcel, new Object[] { cellValue });
                                    }
                                }
                                continue;
                            }
                        }
                    }
                    //--------comExcel无法放入result-无法编译---------------------
                    result.add(comExcel);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

  • 写回答

4条回答 默认 最新

  • CSDNRGY 2017-06-20 05:32
    关注

    这个问题问的有问题
    关闭提问

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题