Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there plans for ImmutableEnumSet in Java 7?

Tags:

I want to have all the efficiencies of EnumSet and pass it around without worrying that somebody would modify it.

like image 793
Alexander Pogrebnyak Avatar asked Aug 30 '10 20:08

Alexander Pogrebnyak


People also ask

What is EnumSet Java?

An enumSet is a Java Collections member, it is not synchronized. An enumSet is a high performing set implementation that works faster than the HashSet. All the elements in an enumSet must be of a single enumeration type that is specified when the set is created.

Is EnumSet immutable?

Yes EnumSet is modifiable.

How do you create an empty EnumSet in Java?

Use EnumSet. noneOf(Class) to create an empty EnumSet.

How do you initialize an enum Set?

Methods of EnumSetCreates an enum set initialized from the specified collection. Creates an enum set with the same element type as the specified enum set, initially containing the same elements (if any). Creates an empty enum set with the specified element type.


Video Answer


1 Answers

You can get an immutable EnumSet with Google collections (Guava).


Resources :

  • Guava home page
  • Google-collections bug tracker - immutable enum set convenience constructor
  • Google documentation - Sets.immutableEnumSet()
like image 152
Colin Hebert Avatar answered Sep 28 '22 18:09

Colin Hebert