简体   繁体   中英

Use of Mono flatMap causes compilation errors

I am attempting to use a Reactor Mono object to process some data. 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.

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.

Am I doing something wrong here? If so, what?

In Mono docs we can read that flatMap should take a function as argument:

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

This function should returns Mono

Your function returns void

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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