Enum.values() vs EnumSet.allOf( ). Which one is more preferable?

后端 未结 6 1250
滥情空心
滥情空心 2020-12-23 09:05

I looked under the hood for EnumSet.allOf and it looks very efficient, especially for enums with less than 64 values.

Basically all sets share the singl

6条回答
  •  粉色の甜心
    2020-12-23 09:40

    You should use the approach which is simplest and clearest to you. Performance shouldn't be a consideration in most situations.

    IMHO: neither option performs very well as they both create objects. One in the first case and three in the second. You could construct a constant which holds all the values for performance reasons.

提交回复
热议问题