EnumMap or HashMap if lookup key is a String

后端 未结 4 1860
花落未央
花落未央 2021-02-03 21:45

I\'m trying to weigh the pros and cons of using an EnumMap over a HashMap. Since, I will always be looking up using a String, it seems tha

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-03 22:26

    First of all, all you keys are final immutable. You should definitely use EnumMap.

    This is like Hash in Ruby:

    options = { :font_size => 10, :font_family => "Arial" }
    

    :font_size is the symbol in Ruby, the final static counterpart in Java.

提交回复
热议问题