Java中枚举的命名:单数或多重? [英] Naming of enums in Java: Singular or Plural?

查看:222
本文介绍了Java中枚举的命名:单数或多重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有关于如何命名Java枚举的官方建议?

 枚举协议{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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆