I have a code which was initially designed for just a single team where they were passing an enum [which stores list of tasks] to an api. This api then progates the use of this enum to many other classes.
Now i have a task where this code needs to be used by multiple teams and they can pass there own set of tasks in form of enums.
Given the current implementation i dont think it is feasible to support multiple teams which completely overhauling the code because enum’s cannot extend other enums.
Is there any way to implement this without massive changes?
But… enums can implement interfaces, for example:
Now we can employ java generic kung fu to specify a generic parameter bounded to a suitable enum:
To use it:
FYI, as a curiosity of generics, you can alternatively use this bound to achieve the same thing:
Although I can find no practical difference in effect, I find it lacks the clarity and familiar pattern of the intersection bound above. For more on this see this question.