Unrivaled EnumSet Version

I can not find the Immutable version of EnumSet . Two questions:

Is it possible to use Enums in a regular Guava ImmutableSet?

If possible, what are some of the advantages / disadvantages of using ImmutableSet instead of EnumSet?

+7
java immutability collections set
source share
2 answers

Are you looking for Sets.immutableEnumSet , perhaps?

Returns an instance of an immutable instance containing data enumerated items. The internally returned set will be supported by EnumSet.

The iteration order of the returned set follows the iteration order of the enumeration, and not the order in which items are displayed in this collection.

+7
source share

Is there a problem with this?

 Collections.unmodifiableSet(myEnumSet); 
+3
source share

All Articles