Hi all, I am using Spring Webflux and I need some help getting some code to compile
Copy code
interface Base
data class Derived(val value: String): Base
fun getDerived(): Mono<Derived> = TODO()
fun getBase(): Mono<Base> = getDerived() // this line does not compile
fun getBase2(): Mono<Base> = getDerived().map { it } // this compiles fine
I am new to kotlin so I might be missing something. But is it possible to get the 4th line to compile without mapping it again?
If this isn’t the right place to ask this please let me know the appropriate channel. Thanks!
t
Tristan Blakers
06/23/2021, 3:55 AM
I'd recommend against using Mono with Webflux. In Webflux + Kotlin, you can use suspend functions, which is a lot more ergonomic
👍 2
j
jush
06/23/2021, 5:50 AM
Change:
Copy code
fun getBase(): Mono<Base> = getDerived() // this line does not compile
to:
Copy code
fun getBase(): Mono<out Base> = getDerived()
d
Deji
06/23/2021, 9:00 PM
thanks Ramon, that fixed the issue.
thanks Tristan, I’ll explore using coroutines instead with webflux.