是否有用于打包枚举的 Java 约定?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36220718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a java convention for packaging enums?
提问by sabrina2020
Is there a Java conventionfor packaging enums? if not is there a best practice? Should I put them all in one package "myapp.enum" or should I put each enum in its related package?
是否有用于打包枚举的 Java约定?如果没有,是否有最佳实践?我应该将它们全部放在一个包“myapp.enum”中还是应该将每个枚举放在其相关包中?
回答by Mureinik
enum
s in Java should be treated like any other class, and should probably be placed in the package that's most related to them. There's no advantage in having a separate "enums" package.
enum
Java 中的 s 应该像对待任何其他类一样对待,并且可能应该放在与它们最相关的包中。拥有单独的“枚举”包没有任何优势。
回答by ACV
enum
is a reserved keyword so you cannot put your enums into the enum
package. Packages could be named after the layers of the application (Model, View, Controller, ..) You are free to choose. The only recommendation is to use unique package names like the reverse domain name of your company: mycompany.com
-> com.mycompany.myapp
...
enum
是保留关键字,因此您不能将枚举放入enum
包中。包可以以应用程序的层(模型、视图、控制器等)命名,您可以自由选择。唯一的建议是使用唯一的包名称,例如贵公司的反向域名:mycompany.com
-> com.mycompany.myapp
...