【问题标题】:Reactor handle operator returns Object?反应堆句柄运算符返回对象?
【发布时间】:2020-09-09 20:07:41
【问题描述】:

我想使用handle 运算符,但它的结果不是我期望的类型,它总是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);
        });

如何获取句柄来识别类型(类似于mapflatMap 识别返回类型)?

我是否总是必须使用cast 运算符?

【问题讨论】:

    标签: spring-webflux project-reactor


    【解决方案1】:

    使用泛型。

        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);
        })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-26
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2020-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多