Java中枚举的命名:单数或多重? [英] Naming of enums in Java: Singular or Plural?
问题描述
枚举协议{HTTP,HTTPS,FTP}
或
枚举协议{HTTP,HTTPS,FTP}
我知道在.Net世界建议使用单数除了代表位标志的枚举。只是好奇,如果在Java中有类似的东西。
一个相关的问题似乎是.Net具体:枚举的单数或复数?
枚举在Java中(通常可能是枚举)应该是单数。想法是你不是选择多个协议,而是选择一个值列表中可能的选择的协议。
注意不存在复数: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
Is there an "official" recommendation of how to name Java enums?
enum Protocol { HTTP, HTTPS, FTP }
or
enum Protocols { HTTP, HTTPS, FTP }
I know in the .Net world the recommendation is to use singular except for enums that represent bit flags. Just curious if there is something similar in Java.
A related question that seems to be .Net specific: Singular or plural for enumerations?
Enums in Java (and probably enums in general) should be singular. The thinking is that you're not selecting multiple Protocols, but rather one Protocol of the possible choices in the list of values.
Note the absence of plurals: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
这篇关于Java中枚举的命名:单数或多重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!