I have a group project in which we are forced to use interfaces and enumerations.
Imagine the situation as shown below:
// marker interface interface Request<T extends Response>{} // marker interface interface Response{} enum TypeAction implements Request<SomeEnumClassThatImplementsResponse>{ TYPE1, TYPE2, TYPE3 } enum OtherTypeAction implements Request<SomeOtherEnumClassThatImplementsResponse>{ OTHERTYPE1, OTHERTYPE2 }
In another class, I have a list of queries like: List<Request> req = new LinkedList<Request>() I want to do the following: create a switch, as shown below:
switch(a_request){ CASE TYPE1: .... CASE TYPE2: .... CASE TYPE3: .... CASE TYPE2: .... CASE OTHERTYPE1: .... CASE OTHERTYPE2: .... }
How can I do it?
IMPORTANT NOTE: I cannot add methods to interfaces or enumerations, but I can create new enumerations that implement the interfaces that you can see above. I would prefer not to have two enumerations that do the same, if possible.
EDIT:. This differs from a possible duplicate answer in that I cannot add any method to the request interface, and therefore I cannot implement the method in enumeration classes.
Thank you in advance
source share