Java generics and reactive paradigm

I’m new to this reactive programming and I’m a little bit lost. I have a simple factory that retrieves the required class that implements a generic interface:

public interface InterfaceToBeImplemented<T> {

    Flux<Tuple2<KafkaEvent<T>, String>> method(List<String> events);
}

public class InterfaceImplemntationOne implements InterfaceToBeImplented<ConcreteObject> {

    @Override
    public Flux<Tuple2<KafkaEvent<ConcreteObject>, String>> method(List<String> events) {
        ....
    }
}

And a service with a factory that retrieves the required implementation calls the method and returns the result:

public class Factory {

    private InterfaceImplementationOne interfaceImplOne;

    public InterfaceToBeImplemented<?> retrieve(SomeClassifier someClassifier) {
        return switch (someClassifier) {
            case 1 -> imterfaceImplOne;
            default -> throw new RuntimeException("Some message");
        };
    }


public class Service {

    private Factory factory;

    public Flux<Tuple2<KafkaEvent<?>, String>> processEvent(List<String> events) {
        return factory.retrieve(eventClassifier)
                .method(events);
    }

This is not working. I get the message:

Required type: Flux<Tuple2<KafkaEvent<?>, String>>
Provided: Flux<Tuple2<? extends KafkaEvent<?>, String>>

And if I change the return type of processEvent I still get the message:

Required type: Flux<Tuple2<? extends KafkaEvent<?>, String>>
Provided: Flux<Tuple2<? extends KafkaEvent<?>, String>>

Leave a Comment