I want to use the handle operator, but the result of it is not the type I expect, it is always Object
Mono.just("lol").handle((string, sink) -> {
if(!string.equals("lol")) {
sink.error(new RuntimeException("not lol!"));
} else {
sink.next(2);
}
}).doOnNext(myInt -> { // expecting myInt to be an integer but is Object
System.out.println(myInt);
});
How can I get handle to recognize the type (similar to how map or flatMap recognizes the return type)?
Do I always have to use the cast operator?
Use generics.
Mono.<String>just("lol").<Integer>handle((string, sink) -> {
if(!string.equals("lol")) {
sink.error(new RuntimeException("not lol!"));
} else {
sink.next(2);
}
}).doOnNext(myInt -> {
System.out.println(myInt);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With