RxJava 代码中出现编译失败“无法找到 concatMap 的符号”

问题描述 投票:0回答:1

我是 RxJava 编码语言的新手。
我正在尝试编写一个函数,以递归方式从一个 S3 位置复制文件并将内容粘贴到另一个 S3 位置。 这是我为此编写的代码

private Single<CopyObjectResponse> copyObjectsRecursively(String sourceBucketName, String sourceKeyPrefix,String destinationBucketName, String destinationKeyPrefix) {
        return listObjects(sourceKeyPrefix, sourceBucketName)
                .concatMap(listObjectsV2Response -> Observable.fromIterable(listObjectsV2Response.contents())
                        .flatMapSingle(s3Object -> {
                            if (s3Object.key().endsWith("/")) {
                                String newSourceKey = s3Object.key();
                                String newDestinationKey = buildDestinationKey(destinationKeyPrefix, newSourceKey, sourceKeyPrefix);
                                return copyObjectsRecursively(sourceBucketName, newSourceKey, destinationBucketName, newDestinationKey);
                            } else {
                                CopyObjectRequest copyRequest = CopyObjectRequest.builder()
                                        .sourceBucket(sourceBucketName)
                                        .sourceKey(s3Object.key())
                                        .destinationBucket(destinationBucketName)
                                        .destinationKey(buildDestinationKey(destinationKeyPrefix, s3Object.key(), sourceKeyPrefix))
                                        .build();
                                return Single.fromFuture(buildClient.copyObject(copyRequest));
                            }
                        }))
                .ignoreElements()
                .toSingleDefault(null)
                .onErrorResumeNext(error -> Single.error(error));
    }

这段代码的问题是,这是在抱怨

cannot find symbol 
[ERROR]   symbol:   method concatMap((listObjec[...] } })) 
[ERROR]   location: class io.reactivex.Single<software.amazon.awssdk.services.s3.model.ListObjectsV2Response>

我已经检查我的代码中是否有正确的导入

import io.reactivex.Single; 
import io.reactivex.Completable; 
import io.reactivex.Observable;

但这还是在抱怨

我尝试查看代码中的所有导入,检查了 RxJava(2.x.x) 的版本,但仍然无法在代码中找到 concatMap 符号。

java compiler-errors rx-java rx-java2
1个回答
0
投票

根据Javadoc,这是在3.0.0版本中引入的

自:
3.0.0

由于您声明使用的是 2.x.x 版本,因此您的版本中不提供此功能。升级 RxJava 或提供不同的实现。

© www.soinside.com 2019 - 2024. All rights reserved.