I’m trying to write a very simple piece of code and can’t figure out an elegant solution to do it:
int count = 0;
jdbcTemplate.query(readQuery, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
realProcessRow(rs);
count++;
}
});
This obviously doesn’t compile. The 2 solutions that I’m aware of both stink:
I don’t want to make count a class field because it’s really a local variable that I just need for logging purposes.
I don’t want to make count an array because it is plain ugly.
This is just silly, there got to be a reasonable way to do it?
A third possibility is to use a final-mutable-int-object, for example:
Apache Commons also have a
MutableIntegerI believe, but I have not used it.