Java Reference
In-Depth Information
The observability of a compilation unit influences the observability of its package
7.4.3 ) .
Types declared in different compilation units can depend on each other, circularly. A Java
compiler must arrange to compile all such types at the same time.
7.4. Package Declarations
A package declaration appears within a compilation unit to indicate the package to which
the compilation unit belongs.
7.4.1. Named Packages
A package declaration in a compilation unit specifies the name (§ 6.2 ) of the package to
which the compilation unit belongs.
PackageDeclaration:
Annotations opt package PackageName ;
The package name mentioned in a package declaration must be the fully qualified name
6.7 ) of the package.
The PackageName in a package declaration ensures there is an observable package
with the supplied canonical name, and that it is not subject to the rules in § 6.5.3 for
determining the meaning of a package name.
The scope and shadowing of a package declaration is specified in § 6.3 and § 6.4 .
The keyword package may optionally be preceded by annotation modifiers. If an annotation
a 9.7 ) on a package declaration corresponds to an annotation type T 9.6 ), and T has a
(meta-)annotation m that corresponds to java.lang.annotation.Target , then m must have an ele-
ment whose value is java.lang.annotation.ElementType.PACKAGE , or a compile-time error oc-
curs.
At most one annotated package declaration is permitted for a given package.
The manner in which this restriction is enforced must, of necessity, vary from im-
plementation to implementation. The following scheme is strongly recommended for
file-system-based implementations: The sole annotated package declaration, if it exists,
is placed in a source file called package-info.java in the directory containing the source
files for the package. This file does not contain the source for a class called package-
info.java ; indeed it would be illegal for it to do so, as package-info is not a legal identifier.
Typically package-info.java contains only a package declaration, preceded immediately
Search WWH ::




Custom Search