代码之家  ›  专栏  ›  技术社区  ›  John Lippson

Java中有保留的包名吗?

  •  4
  • John Lippson  · 技术社区  · 8 年前

    我有个包裹 com.test.mythingimport .理想情况下,我希望这个名字 com.test.mything.import .你能说出你的名字吗 import 还是会引起冲突?

    2 回复  |  直到 8 年前
        1
  •  15
  •   Silvio Mayolo    8 年前

    从…起 JLS §7.4.1

    编译单元中的包声明指定编译单元所属包的名称(§6.2)。

    PackageDeclaration:
     {PackageModifier} package Identifier {. Identifier} ; 
    

    哪里 Identifier 定义在 JLS §3.8 像

    Identifier:
     IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral 
    

    因此,包名不能是关键字(例如 import ),布尔值( true 或 false )或者 null .

        2
  •  -1
  •   nasukkin    8 年前

    包名由Java中文件结构的约定驱动。如果你想让你的包裹被命名 com.test.mything.import ,您的包裹需要放在 /com/test/mything/import 目录(根是项目源代码的根)。