Order of automatically imported packages and ambiguity

后端 未结 3 1901
醉话见心
醉话见心 2021-01-13 01:39

JLS: Chapter 7. Packages:

A package consists of a number of compilation units (§7.3). A compilation unit automatically has access to all types

3条回答
  •  天命终不由人
    2021-01-13 02:31

    Actually the issue is about simple type names:

    6.5.5.1 Simple Type Names If a type name consists of a single Identifier, then the identifier must occur in the scope of exactly one visible declaration of a type with this

    About scope we can read here:

    (6.3) The scope of a declaration is the region of the program within which the entity declared by the declaration can be referred to using a simple name, provided it is visible

    ..

    The scope of a type imported by a single-type-import declaration (§7.5.1) or a type-import-on-demand declaration (§7.5.2) is all the class and interface type declarations (§7.6) in the compilation unit in which the import declaration appears, as well as any annotations on the package declaration (if any) of the compilation unit .

提交回复
热议问题