【发布时间】:2021-01-19 19:51:39
【问题描述】:
我有以下功能
public Mono<CarAndShip> getCarAndShip(Long id) {
Mono<Car> carMono = carService.getCar(id).subscribeOn(Schedulers.elastic());
Mono<Ship> shipMono = shipService.getShip(id).subscribeOn(Schedulers.elastic());
return Mono.zip(carMono, shipMono)
.flatMap(zipMono -> {
return new CarAndShip(zipMono.getT1(), zipMono.getT2());
});
IntelliJ 在返回声明中抱怨:
Required type: Mono <CarAndShip>
Provided: Mono <Object> no
instance(s) of type variable(s) R exist so that CarAndShip conforms to Mono<? extends R>
如何将类型转换为所需的CarAndShip 返回类型?
【问题讨论】:
-
您的
CarAndShip班级是什么样的?为什么不直接返回Mono<Tuple2<Car, Ship>>?
标签: java spring-webflux reactor-netty