组合包名称的命名约定

Naming conventions of composed package names

我想创建一个名为 form validator 的包。

是不是写的比较好

我想提一下,我想避免 form.validatorform-validator 禁止的 .

包名全部小写以避免与类或接口的名称冲突。所以

  • form_validator
  • formvalidator.

详情见here

来自 documentation 包命名约定:

Package names are written in all lower case to avoid conflict with the names of classes or interfaces

所以这会给你留下以下两种可能性:

form_validator
formvalidator

其实文档也说的很清楚,下划线在包名中有特殊的作用:

if the package name begins with a digit or other character that is illegal to use as the beginning of a Java name, or if the package name contains a reserved Java keyword, such as "int" ... the suggested convention is to add an underscore.

因此,仅在特殊情况下才建议使用下划线,您的命名问题似乎不属于这种情况。所以我会推荐 formvalidator 作为包名。

最常规的是第三个:formvalidator

Google Java Style guide 注释:

5.2.1 Package names

Package names are all lowercase, with consecutive words simply concatenated together (no underscores). For example, com.example.deepspace, not com.example.deepSpace or com.example.deep_space.

正如@teppic 所说,Oracle Java Docs 声明

Package names are written in all lower case to avoid conflict with the names of classes or interfaces.

在 Java 中,包名称全部 小写 。这意味着以下将是最理想的包装名称。

formvalidator

这也被接受。

form_validator