Java Reference
In-Depth Information
It is not a compile-time error to name the current package or
java.lang
in a type-import-on-
demand declaration. The type-import-on-demand declaration is ignored in such cases.
Example 7.5.2-1. Type-Import-on-Demand
import java.util.*;
causes the simple names of all
public
types declared in the package
java.util
to be avail-
able within the class and interface declarations of the compilation unit. Thus, the
simple name
Vector
refers to the type
Vector
in the package
java.util
in all places in the
compilation unit where that type declaration is not shadowed (§
6.4.1
) or obscured
The declaration might be shadowed by a single-type-import declaration of a type
whose simple name is
Vector
; by a type named
Vector
and declared in the package to
which the compilation unit belongs; or any nested classes or interfaces.
The declaration might be obscured by a declaration of a field, parameter, or local vari-
able named
Vector
.
(It would be unusual for any of these conditions to occur.)
Two or more type-import-on-demand declarations in the same compilation unit may name
the same type or package. All but one of these declarations are considered redundant; the
effect is as if that type was imported only once.
If a compilation unit contains both a type-import-on-demand declaration and a static-
import-on-demand declaration (§
7.5.4
) that name the same type, the effect is as if the
static
7.5.3. Single-Static-Import Declarations
A
single-static-import declaration
imports all accessible
static
members with a given simple
name from a type. This makes these
static
members available under their simple name in
the class and interface declarations of the compilation unit in which the single-static-import
declaration appears.
SingleStaticImportDeclaration:
import static
TypeName
.
Identifier
;
The
TypeName
must be the canonical name (§
6.7
) of a class type, interface type, enum
type, or annotation type.