代码清单:
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;
}
无法编译并显示以下消息:
接口 java.util.stream.Stream<T> 中的方法映射不能应用于给定类型;[错误] 必需:java.util.function.Function<? 超级 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] 原因:无法推断类型变量 R [ERROR](参数不匹配; java.util.function.Function<org.apache.commons.dbutils.handlers.MapListHandler,R>不能转换成java.util.function.Function<? super java.util.Map<java.lang.String,java .lang.Object>,? 扩展 R>)