组合包名称的命名约定 [英] Naming conventions of composed package names

查看:77
本文介绍了组合包名称的命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to create a package named form validator.

写的更好吗

  • form_validator,
  • formValidator
  • formvalidator?

我想提一下,我想避免 form.validator.而那个 form-validator禁止的.

I want to mention that I want to avoid form.validator. And that form-validator is forbidden.

推荐答案

来自 关于包命名约定的文档:

包名全部小写,避免与类名或接口名冲突

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

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

So this would leave you with the following two possibilities:

form_validator
formvalidator

其实文档也明确了下划线在出现在包名中时起到了特殊的作用:

Actually the documentation also makes it clear that underscore plays a special role when it appears in package names:

如果包名以数字或其他字符开头,作为 Java 名称的开头是非法的,或者包名包含保留的 Java 关键字,例如int"……建议的约定是添加下划线.

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 作为包名.

So, underscore is suggested only in special cases, into which your naming problem does not seem to fall. So I would recommend formvalidator as the package name.

这篇关于组合包名称的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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