java反射获取对象某些属性值

private void headleDataByProxy(Object object, int rowNum, HSSFCellStyle styleCell, HSSFRow row){
    Class aClass = object.getClass();
    // 获取属性
    for(int i =1;i<11;i++) {
        try {
            Field field = aClass.getDeclaredField("year" + i);
            field.setAccessible(true);
            Cell cell = row.createCell(rowNum + i);
            String valueStr = field.get(object).toString();
            // 填充数据
            cell.setCellValue(valueStr);
            cell.setCellStyle(styleCell);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}

你可能感兴趣的:(java,java,jvm,开发语言)