不存在类型变量U的实例,因此Row符合Iterable <?扩展U>

时间:2019-07-02 09:59:52

标签: java generics rx-java guava

我有一个返回ResultSet的Observable的方法:

public static Observable<ResultSet> queryAllAsObservable(Session session, String query, Object... partitionKeys) {
    List<ResultSetFuture> futures = sendQueries(session, query, partitionKeys);
    Scheduler scheduler = Schedulers.io();
    List<Observable<ResultSet>> observables = Lists.transform(futures, (ResultSetFuture future) -> Observable.fromFuture(future, scheduler));
    return Observable.merge(observables);
}

现在,我需要创建此方法的版本,而不是返回Row的Observable。这是我尝试过的:

public static Observable<Row> queryAllAsRowObservable(Session session, String query, Object... partitionKeys) {
    List<ResultSetFuture> futures = sendQueries(session, query, partitionKeys);
    Scheduler scheduler = Schedulers.io();
    List<Observable<ResultSet>> observables = Lists.transform(futures, (ResultSetFuture future) -> Observable.fromFuture(future, scheduler));
    return Observable.merge(observables).flatMapIterable(item -> item.one());
}

但是item -> item.one()带有错误标记:

no instance(s) of type variable(s) U exists so that Row conforms to Iterable<? extends U>

1 个答案:

答案 0 :(得分:1)

flatMapIterable在尝试执行此操作时,其类型错误。您可以使用map代替flatMapIterable,也可以重新考虑使用merge