0
votes

I am pretty new in reactive programming, I am using last Spring 5 Webflux framework and playing with so project reactor. I am facing an issue, I would like to use Mono with this inheritance schema :

Client extends User

I created this method :

public Mono<User> saveUser(Mono<User> userToSave)
{
    return userToSave.doOnNext(u -> {
        // Some stuff
    });
}

I cannot now use this method with a Mono< Client > as parameter in spite of Client extends from User.

Mono<Client> client = ...
instance.saveUser(client); <-- Error

How can I achieve this ? Do I try something bad ?

Thank you a lot

1

1 Answers

3
votes

That's a java inheritance "problem": you need to declare your method as:

public Mono<User> saveUser(Mono<? extends User> userToSave)

(this is known as a covariant generic type. the guidance is "be more lenient in what you consume", as the rule of thumb consume == extends)