简体   繁体   English

使用 Mono flatMap 会导致编译错误

[英]Use of Mono flatMap causes compilation errors

I am attempting to use a Reactor Mono object to process some data.我正在尝试使用 Reactor Mono 对象来处理一些数据。 I am attempting to use the FlatMap lambda in a manner that is shown in the documentation I read, but I am having some compilation problems.我正在尝试以我阅读的文档中显示的方式使用 FlatMap lambda,但我遇到了一些编译问题。

The code I am using is simple test code:我使用的代码是简单的测试代码:

Mono<String> astring = Mono.just("Testing some string data");

astring.flatMap(test-> {
   System.out.println("Test String: "+test);
});

I am getting the following compilation error:我收到以下编译错误:

The method flatMap<Function<? Super String> extends Mono<? extends R> in the type Mono<String> is not applicable for the arguments ((<no type> test) ->{}

I do not understand what is wrong here.我不明白这里有什么问题。 I am using the exact syntax that is shown in every document I have read about using flatMap with Mono.我正在使用我读过的关于在 Mono 中使用 flatMap 的每个文档中显示的确切语法。

Am I doing something wrong here?我在这里做错了吗? If so, what?如果是这样,是什么?

In Mono docs we can read that flatMap should take a function as argument:Mono文档中,我们可以读到 flatMap 应该将函数作为参数:

flatMap(Function<? super T,? extends Mono<? extends R>> transformer)

This function should returns Mono这个函数应该返回Mono

Your function returns void您的函数返回void

flatMap() (和map() )用于转换您的数据 - 您只是显示值,因此您想使用doOnNext()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM