私はインターフェースを持っています
public interface TerminalSymbol {
// methods ...
}
列挙型
// common usage enum that I need
public enum Common implements TerminalSymbol {
EPSILON;
@Override
// methods ...
}
そして、私は次のようなことをしたいと思います:
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
そのエラーは(私の場合):
The method add(capture#1-of ? extends TerminalSymbol) in the type AbstractCollection<capture#1-of ? extends TerminalSymbol> is not applicable for the arguments (Common)
を使用すればSet<SomeInterface>
、この種のエラーを防ぐことができる (そして、正式な文法を表すクラスの開発を続行できる) ことがわかりましたEnumSet
が、HashSet
. どうすればこの問題を解決できますか?