I have classes A, B with B extends A
I have interface defined as
public interface MyProcessor<EVENT> {
void processEvent(EVENT event);
}
I have two implementations
public class EventAProcessor implements EventProcessor<A> {
@Override
public void processEvent(A a) {
}
public class EventBProcessor implements EventProcessor<B> {
@Override
public void processEvent(B b) {
}
there is common processing so I decided to extend BProcessor from Aprocessor
public class EventBProcessor extends EventAProcessor implements EventProcessor<B> {
}
This is where it fails with the message
MyProcessor cannot be inherited with different arguments: <A> and <B>
I have other solutions to workaround my problem, but just wondering, how to get this working.
You should introduce an abstract generic class:
Your other classes will then inherit common functionality as such:
This doesn’t necessarily have to do with generics. It’s a general way to approch polymorphism in object-oriented programming.