1

I'm looking for a class like EnumMap, except for enum type values (ie. EnumValueMap<K,V extends Enum<V>>).

http://java.sun.com/javase/6/docs/api/java/util/EnumMap.html

Edit


If I was mapping, say, a few million Objects to 10 enum types, I imagined it would at least be possible to create a more memory-efficient implementation than just using HashMap<Object, V extends Enum<V>>. Perhaps not.

1
  • Which benefits do you expect from such a class? EnumMap have compact and efficient implementation, because values are stored in array and ordinals of Enum constants are indices in that array. But mapping from Objects to Enums probalby wouldn't have any implementation benefits, so you can use any map implementation. Commented Jan 3, 2010 at 0:06

2 Answers 2

2

I'd like to map Objects to enum type values. I'm looking for something with a Map interface, not a Set interface.

Well it sounds that what you need is a HashMap<Object, V extends Enum<V>>.

Sign up to request clarification or add additional context in comments.

Comments

1

You can any Map implementation you like (such as HashMap). enums in Java are classes and their values are objects, they don't need a special treatment.

Note that the same is true for enums as keys. EnumMap (and EnumSet) is simply optimized for enums and therefore can be faster/use less memory/...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.