I have following classes:
public class A extends Exception {
}
public class B extends Email {
}
My goal is to implement some strategy that would be able to work with both those classes like below:
For instance:
public enum Strategy {
ACTION_1 {
@Override
public void handleAction(Class<? extends Exception > parameterThatShouldAcceptOnlyA) {
throw parameterThatShouldAcceptOnlyA;
}
},
ACTION_2 {
@Override
public void handleAction(Class<? extends Email > parameterThatShouldAcceptOnlyB) {
parameterThatShouldAcceptOnlyB.send();
}
};
public abstract void handleAction(Class<?> parameterThatShouldAcceptBoth);
}
This is not compiled through incorrect generic in overriden methods.
Could you please suggest how it would be possible to make this workable?