Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when and why do use JumboEnumSet

I have suffered about JumboEnumSet, but did not find much information about.
when and why do we use JumboEnumSet.Please can anyone explain about JumboEnumSet?

like image 960
developer Avatar asked Mar 20 '12 07:03

developer


People also ask

What is the use of EnumSet?

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.

What is EnumSet?

An EnumSet is a specialized Set collection to work with enum classes. It implements the Set interface and extends from AbstractSet: Even though AbstractSet and AbstractCollection provide implementations for almost all the methods of the Set and Collection interfaces, EnumSet overrides most of them.

Is EnumSet immutable?

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 .


2 Answers

You don't need to use it explicitly - it's just an implementation detail. Basically, when an enum is small, EnumSet can use a very efficient representation of the enum as a single int or long (I forget which) with one bit per member. When it has more elements than that representation allows, JumboEnumSet is used instead.

You don't need to worry about this - just use the members on EnumSet and you'll be fine. Just be aware that if your enums go over a certain size, then enum sets become more expensive and less efficient.

like image 134
Jon Skeet Avatar answered Oct 04 '22 16:10

Jon Skeet


Don't worry about it.

You can't use the class directly because it is declared as package private. And you shouldn't, since it is described in its javadoc as a "private implementation class".

like image 37
Stephen C Avatar answered Oct 04 '22 17:10

Stephen C