Consider the following code:
public static Mono<String> myFunction(boolean condition) {
if (condition) {
// returns Mono<String>
return Mono.fromSupplier(() -> "Hello, World!");
} else {
// returns Mono<Void>
return Mono.fromRunnable(() -> System.out.println("Running a task..."));
}
}
This code compiles and run perfectly fine. Mono.fromSupplier
returns String
, whereas Mono.fromRunnable
returns Mono<Void>
, then ideally compilation should fail. What am I missing?