Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactor handle operator returns Object?

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?

like image 329
ooomid Avatar asked Sep 07 '26 20:09

ooomid


1 Answers

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);
    })
like image 111
K.Nicholas Avatar answered Sep 12 '26 17:09

K.Nicholas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!