ooo*_*mid 6 project-reactor spring-webflux
我想使用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);
});
Run Code Online (Sandbox Code Playgroud)
如何获取句柄来识别类型(类似于如何map或flatMap识别返回类型)?
我总是需要使用cast操作员吗?
K.N*_*las 11
使用泛型。
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);
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2221 次 |
| 最近记录: |