I have an interface
public interface TerminalSymbol {
// methods ...
}
an enum
// common usage enum that I need
public enum Common implements TerminalSymbol {
EPSILON;
@Override
// methods ...
}
and I'd like to do something like:
enum Term implements TerminalSymbol {
A, B, C, ...
@Override
// methods ...
}
EnumSet<? extends TerminalSymbol> terminalSymbols = EnumSet.allOf(Term.class);
terminalSymbol.add(Common.EPSILON); // this line gives me error
and that error is (in my case):
The method add(capture#1-of ? extends TerminalSymbol) in the type AbstractCollection<capture#1-of ? extends TerminalSymbol> is not applicable for the arguments (Common)
now I know that if I use Set<SomeInterface>
I could prevent this type of error (and I could continue with my developing of my class representing a formal grammar) but I'd like to use EnumSet
because it's likely to be more efficient than HashSet
. How can I solve this problem?