在java中粘贴是什么单词,Java包名称中的单词分隔符的约定是什么?

How should one separate words in package names? Which of the following are correct?

com.stackoverflow.my_package (underscore)

com.stackoverflow.my-package (hyphens)

com.stackoverflow.MyPackage (CamelCase)

What is the general standard?

解决方案

Here's what the official naming conventions document prescribes:

Packages

The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981.

Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names.

Examples

com.sun.eng

com.apple.quicktime.v2

edu.cmu.cs.bovik.cheese

References

Note that in particular, anything following the top-level domain prefix isn't specified by the above document. The JLS also agrees with this by giving the following examples:

com.sun.sunsoft.DOE

gov.whitehouse.socks.mousefinder

com.JavaSoft.jag.Oak

org.npr.pledge.driver

uk.ac.city.rugby.game

The following excerpt is also relevant:

In some cases, the internet domain name may not be a valid package name. Here are some suggested conventions for dealing with these situations:

If the domain name contains a hyphen, or any other special character not allowed in an identifier, convert it into an underscore.

If any of the resulting package name components are keywords then append underscore to them.

If any of the resulting package name components start with a digit, or any other character that is not allowed as an initial character of an identifier, have an underscore prefixed to the component.

References

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值