I'd like to create a JComboBox that handles the selection of any Enum given to it. For that I need a method to retrieve all the available values of the Enum passed to the JComboBox. As I don't know the specific Enum I can't call EnumType.values()
. I could think of some complicated solutions where supported Enums would have to implement some interface I define, but I guess I am missing a simpler, more general solution. What is the way I should go?
values() is a static method of Enum , which always returns the values in same order.
The idea is to use the Enum. GetValues() method to get an array of the enum constants' values. To get an IEnumerable<T> of all the values in the enum, call Cast<T>() on the array. To get a list, call ToList() after casting.
You cannot have an enum extend another enum , and you cannot "add" values to an existing enum through inheritance.
equals method uses == operator internally to check if two enum are equal. This means, You can compare Enum using both == and equals method.
Class.getEnumConstants()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With