`
leonzhx
  • 浏览: 774131 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Item 31: Use instance fields instead of ordinals

阅读更多

1.  All enums have an ordinal method, which returns the numerical position of each enum constant in its type.

 

2.  Never derive a value associated with an enum from its ordinal; store it in an instance field instead.

 

3.  ordinal is designed for use by general-purpose enum based data structures such as EnumSet and EnumMap. Unless you are writing such a data structure, you are best off avoiding the ordinal method entirely.

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics