Is there any performance benefit one way or another? Is it compiler/VM specific? I am using Hotspot.
I would like to add to the other great answers here that it also depends on your flow, for example:
Public class MyDao {
private String sql = "select * from MY_ITEM";
public List getAllItems() {
springJdbcTemplate.query(sql, new MyRowMapper());
};
};
Pay attention that you create a new MyRowMapper object per each call.
Instead, I suggest to use here a static field.
Public class MyDao {
private static RowMapper myRowMapper = new MyRowMapper();
private String sql = "select * from MY_ITEM";
public List getAllItems() {
springJdbcTemplate.query(sql, myRowMapper);
};
};