gpt4 book ai didi

android - 可迭代的 .zip 问题 (rxJava)

转载 作者:行者123 更新时间:2023-11-29 15:35:02 25 4
gpt4 key购买 nike

我有四个 Observable 的代码。我将 Observable.zip 应用到它们:

Observable<Currencies> usd = CoinMarket.getMarketApi().getCurrencies();
Observable<Currencies> rub = CoinMarket.getMarketApi().getCurrencies("RUB");
Observable<Currencies> eur = CoinMarket.getMarketApi().getCurrencies("EUR");
Observable<Currencies> btc = CoinMarket.getMarketApi().getCurrencies("BTC");

List<Observable<Currencies>> singles = new ArrayList<>();
singles.add(usd);
singles.add(rub);
singles.add(eur);
singles.add(btc);

Observable<Currencies> c = Observable.zip(singles, new Function<Currencies[], Currencies>() {
@Override
public Currencies apply(@NotNull Currencies[] objects) throws Exception {
return ramming(objects);
}
});

但是我得到了错误:

enter image description here

消息说未找到具有此类签名的方法(也许我不对),但我去声明并查看签名,有点像,是合适的。

 public static <T, R> Observable<R> zip
(Iterable<? extends ObservableSource<? extends T>> sources,
Function<? super Object[], ? extends R> zipper)

我做错了什么?

P.S:我注意到这个错误 RxJava2Iterableisbroken

最佳答案

这不是错误。你需要一个Function<? super Object[]由于 Java 的泛型限制。这也在 the Javadocs of zips 中进行了解释。 .

Observable<Currencies> usd = CoinMarket.getMarketApi().getCurrencies();
Observable<Currencies> rub = CoinMarket.getMarketApi().getCurrencies("RUB");
Observable<Currencies> eur = CoinMarket.getMarketApi().getCurrencies("EUR");
Observable<Currencies> btc = CoinMarket.getMarketApi().getCurrencies("BTC");

List<Observable<Currencies>> singles = new ArrayList<>();
singles.add(usd);
singles.add(rub);
singles.add(eur);
singles.add(btc);

Observable<Currencies> c = Observable.zip(singles, new Function<Object[], Currencies>() {
@Override
public Currencies apply(@NotNull Object[] objects) throws Exception {
Currencies[] currencies = new Currencies[objects.length];
for (int i = 0; i < objects.length; i++) {
currencies[i] = (Currencies)objects[i];
}
return ramming(currencies);
}
});

关于android - 可迭代的 .zip 问题 (rxJava),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52579715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com