I’m wondering the performance of reflection in this situation. I’m iterating a (probably) large excel file (let’s say 3000 max) which it’s going to be done from time to time, and the implementation that my mate is something like this, iterating each row:
while (cells.hasNext()) {
XSSFCell cell = (XSSFCell) cells.next();
String cellData = this.getCellData(cell);
if (cellData.trim().isEmpty()) {
break;
}
Field field = RowPrestacionVO.class.getField(fields.get(idx));
field.set(vo, cellData);
idx++;
}
Is there any probability that I’m going to have some performance issues iterating like that?
2
While reflection is slow, doing it a handful of thousand times while processing a file will probably not be an issue: the file access is likely to be slower still.
Still, you should be able to improve the performance of the code you posted by moving the initiation of ‘ field’ outside of your loop.