I can't find an Immutable version of EnumSet. Two questions:
Can I use Enums in a normal Guava ImmutableSet?
If I can, what are some benefits/drawbacks of using an ImmutableSet instead of the EnumSet?
Yes EnumSet is modifiable. If you want to create an immutable EnumSet then go for immutableEnumSet. Returns an immutable set instance containing the given enum elements. Internally, the returned set will be backed by an EnumSet .
EnumMap is a specialized implementation of the Map interface for the enumeration types. EnumSet is a specialized implementation of the Set interface for the enumeration types. EnumMap is internally represented as an array. EnumSet is internally represented as a BitVector.
The EnumSet is one of the specialized implementations of the Set interface for use with the enumeration type. A few important features of EnumSet are as follows: It extends AbstractSet class and implements Set Interface in Java. EnumSet class is a member of the Java Collections Framework & is not synchronized.
Use EnumSet. noneOf(Class) to create an empty EnumSet.
Are you looking for Sets.immutableEnumSet
(Guava) perhaps?
Returns an immutable set instance containing the given enum elements. Internally, the returned set will be backed by an EnumSet.
The iteration order of the returned set follows the enum's iteration order, not the order in which the elements appear in the given collection.
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