The code listing:
protected List<R> getRows(String startDate, String endDate, Function<MapListHandler, R> func){
ConnectionManager cm = new ConnectionManager();
List<R> rows = null;
try(Connection c = cm.getConnection()) {
String sql = getSql();
rows = new QueryRunner()
.query(c, sql, new MapListHandler(), startDate, endDate, startDate, endDate)
.stream()
.map(func).collect(Collectors.toList());
} catch (SQLException e) {
e.printStackTrace();
}
finally {
cm.closeConnection();
}
return rows;
}
fails to compile with the following message:
method map in interface java.util.stream.Stream<T> cannot be applied to given types; [ERROR] required: java.util.function.Function<? super java.util.Map<java.lang.String,java.lang.Object>,? extends R> [ERROR] found: java.util.function.Function<org.apache.commons.dbutils.handlers.MapListHandler,R> [ERROR] reason: cannot infer type-variable(s) R [ERROR] (argument mismatch; java.util.function.Function<org.apache.commons.dbutils.handlers.MapListHandler,R> cannot be converted to java.util.function.Function<? super java.util.Map<java.lang.String,java.lang.Object>,? extends R>)
Function<Map<String, Object>, R> func
becauseMap<String, Object>
is the type of the Stream elements. What's your question? – Stefan Zobel