在java中使用数字作为包名 [英] Using numbers as package names in java
问题描述
我已经检查了以下帖子:
I have checked the following posts already:
https://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#jls-6.2
和所以发布:
和
什么包命名你在 Java 中使用个人/业余爱好项目的约定吗?
我尝试创建一个这样的包:
I tried creating a package like this:
package 01;
public class Test
{
// ...
}
当我编译我得到这个:
I:\code>javac 01\Test.java
01\Test.java:1: error: <identifier> expected
package 01;
^
1 error
我正在寻找名称的语法正确性,而不是约定俗成.
是否有一个 oracle/SUN 引用列出了一个包的语法,或者它是否遵循与 java 中变量名相同的规则?可能是 Java 语言规范中的一个参考,说包名遵循与变量名相同的规则.
Is there a oracle/SUN reference that lists out the syntax for a package or does it follow the same rules as for variable names in java? May be a reference in the Java Language Specification saying package names follow the same rules as variable names.
推荐答案
这个链接到Java使用的标识符语法,它适用于所有提到标识符的地方,包括但不限于包名.所以 01
绝对不是一个有效的包名,因为它不是一个有效的标识符.
This links to identifier grammar that Java uses, which applies everywhere identifier is mentioned, including but not limited to package name. So 01
is definitely not a valid package name, since it's not a valid identifier.
这篇关于在java中使用数字作为包名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!