Java Reference
In-Depth Information
The observability of a compilation unit influences the observability of its package
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
which the compilation unit belongs.
PackageDeclaration:
Annotations
opt
package
PackageName
;
The package name mentioned in a
package
declaration must be the fully qualified name
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 keyword
package
may optionally be preceded by annotation modifiers. If an annotation
(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