番石榴中是否有相应的不可变enumMap? [英] Is there a corresponding immutable enumMap in guava?

查看:313
本文介绍了番石榴中是否有相应的不可变enumMap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近了解了EnumMap在Java中的优点,并希望将现有的 ImmutableMap< OccupancyType,BigDecimal> 替换为EnumMap。但是,我也喜欢ImmutableMap提供的不可变属性。

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.


  • 是否有一个变体,在guava中可用的ImmutableEnumMap?

  • 在存储方面哪一个(EnumMap与ImmutableMap)表现更好?

  • 我找不到两者的比较。如果有人能指出我的链接或对两种数据结构的效率有一些见解,我会很感激吗?

推荐答案

这里的番石榴贡献者。

Guava目前没有 ImmutableEnumMap 变体,但如果确实如此,它可能只是 EnumMap 的包装器。 (也就是说,稍微好一点的不可变实现是可能的。)

Guava doesn't currently have an ImmutableEnumMap variant, but if it did, it would probably just be a wrapper around an EnumMap. (That said, slightly better immutable implementations are possible.)

EnumMap 的性能优于基本的 ImmutableMap ,无论如何;很难或不可能击败。

EnumMap will perform better than the basic ImmutableMap, in any event; it's difficult or impossible to beat.

(我将提出问题以调查为枚举密钥类型添加 ImmutableMap 变体。)

(I'll file an issue to investigate adding an ImmutableMap variant for enum key types, though.)

更新:Guava 14添加 Maps.immutableEnumMap()

Update: Guava 14 adds Maps.immutableEnumMap().

这篇关于番石榴中是否有相应的不可变enumMap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆