I\'m trying to find a way to iterate through an enum\'s values while using generics. Not sure how to do this or if it is possible.
The following code illustrates
If you are sure that selectedOption
of the constructor Filter(T selectedOption)
is not null. You can use reflection. Like this.
public class Filter {
private List availableOptions = new ArrayList();
private T selectedOption;
public Filter(T selectedOption) {
this.selectedOption = selectedOption;
for (T option : this.selectedOption.getClass().getEnumConstants()) { // INVALID CODE
availableOptions.add(option);
}
}
}
Hope this helps.