How to efficiently use Enum objects as keys in the Map data structure?

后端 未结 3 389
慢半拍i
慢半拍i 2021-01-20 05:08

Is there a more efficient and specialized implementation of a Map collection where Enum objects can serve as keys?

3条回答
  •  太阳男子
    2021-01-20 05:44

    BTW, it's simpler to write:

    Map map = new EnumMap<>(MyEnum.class);
    

    There's no need to repeat the types. This can make the code a lot easier to read.

提交回复
热议问题