Declare an interface for the follower
field.
public interface Follower {
// any methods
}
And have both the enums implement that interface.
public enum Connector implements Follower {
AND, OR, XOR;
}
enum Component implements Follower {
ACTIVITY
}
Then you can declare your field:
Follower follower = Connector.OR;
Or
Follower follower = Component.ACTIVITY;
This has a couple distinct advantage over declaring the field as an Enum<? extends Follower>
(that I can think of). With this way you are free to add methods to the Follower
interface without having to modify fields in the future, whereas you have no control over the Enum
type, so if you decided that Follower
s needed a method, you would have to change the declaration in every place. This may never be the case with your scenario, but with so little cost to use this way, it's good defensive practice.
A second, slightly less important advantage, which is more about taste: it avoids the generics in the type which, when you include wildcards, can become less readable.