Java Reference
In-Depth Information
nested inside a generic type declaration can be imported, but its outer type is always
erased.
If two single-type-import declarations in the same compilation unit attempt to import types
with the same simple name, then a compile-time error occurs, unless the two types are the
same type, in which case the duplicate declaration is ignored.
If the type imported by the single-type-import declaration is declared in the compilation
unit that contains the
import
declaration, the
import
declaration is ignored.
If a single-type-import declaration imports a type whose simple name is
n
, and the com-
pilation unit also declares a top level type (§
7.6
) whose simple name is
n
, a compile-time
error occurs.
If a compilation unit contains both a single-type-import declaration that imports a type
whose simple name is
n
, a compile-time error occurs.
Example 7.5.1-2. Duplicate Type Declarations
This program:
import java.util.Vector;
class Vector { Object[] vec; }
causes a compile-time error because of the duplicate declaration of
Vector
, as does:
import java.util.Vector;
import myVector.Vector;
where
myVector
is a package containing the compilation unit:
package myVector;
public class Vector { Object[] vec; }
Example 7.5.1-3. No Import of a Subpackage
Note that an
import
statement cannot import a subpackage, only a type.
For example, it does not work to try to import
java.util
and then use the name
util.Random
to refer to the type
java.util.Random
:
import java.util;