I have several enums that implement the interface Word
. I want to generate a list of all of the values of these enums.
The way I am currently doing this is:
public Set<Word> allWords() {
Set<Word> dictionary = new HashSet<>();
dictionary.addAll(Arrays.asList(Article.values()));
dictionary.addAll(Arrays.asList(Conjunction.values()));
dictionary.addAll(Arrays.asList(Verb.values()));
// And so on...
return dictionary;
}
Is there a way to iterate over these enums? I imagine it would involve creating a list of Class objects, but I'm not sure how to convert that back the the actual values.
In case it's relevant, Word and each of the enums are in the same package (lexicon).