I recently learnt about the benefits of EnumMap in Java and would like to replace the existing ImmutableMap<OccupancyType, BigDecimal> to EnumMap. However, I’d also like the immutable property offered by ImmutableMap.
- Is there a variant, ImmutableEnumMap available in guava ?
- In terms of storage which one (EnumMap vs ImmutableMap) performs better ?
- I couldn’t find a comparison of the two. I’d appreciate if someone can point me to a link or give some insights on the efficiency of the two data structures ?
Guava contributor here.
Guava doesn’t currently have an
ImmutableEnumMapvariant, but if it did, it would probably just be a wrapper around anEnumMap. (That said, slightly better immutable implementations are possible.)EnumMapwill perform better than the basicImmutableMap, in any event; it’s difficult or impossible to beat.(I’ll file an issue to investigate adding an
ImmutableMapvariant for enum key types, though.)Update: Guava 14 adds
Maps.immutableEnumMap().