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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器