Alex Rivera | Logout

Why EnumSet is implemented as abstract class and EnumMap is implemented as concrete class?

Asked 2011-03-03T14:47:35.540
24

I was wondering, is there any reason why EnumSet is implemented as abstract class and EnumMap is implemented as concrete class?

Edit
Report

1 Answer

7

EnumSet uses two implementations, RegularEnumSet and JumboEnumSet, depending on the size of your enum (64 elements being the threshold). The factory methods delegate to the appropriate implementation.

EnumMap on the other hand works the same for all enum types (it keeps an array of all enum items and an equally-sized array of values), so there's no need for an abstract class.

answered 2011-03-03T14:55:07.987

Your Answer