Alexandru-Constantin Bledea opened SPR-17148 and commented
I have encountered many times after changing the java8 code to use lambdas rather than strict objects that the compiler chooses the wrong method.
Because both RowCallbackHandler and ResultSetExtractor have the same lambda signature, the compiler can get confused sometimes and call the method that i wasn't intending to call.
I have found that in few places calls to jdbcTemplate.query(...,(rs) -> something(rs)) will be interpreted as calls to the RowCallbackHandler rather than ResultSetExtractor and there is no indication that this is happening.
Perhaps now with lambdas becoming more common place it would make sense to deprecate these methods and replace them with more explicit calls like queryWithHandler and queryWithExtractor so that we can be sure that we're calling the correct type?
No further details from SPR-17148
Comment From: spring-projects-issues
Alexandru-Constantin Bledea commented
I also want to add the fact that under normal circumstances the code works as expected, whenever the autodetection mechanism fails is because the applicatiion code is wrong (for instance returning void rather than Void)
But having explicit names would warn you immediately that you are doing it wrong and you would know to change the return type.
Comment From: snicoll
JdbcTemplate
(and others) have a long history and breaking users for this reason doesn't sound like an improvement. In the meantime, JdbcClient
offers a more fluent interface that doesn't have the problem you've described. Thanks for the suggestion, in any case.