
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Package Syntax
|
241
the compiler will subsequently treat the unqualified reference SpaceShip as though it
were literally game.vehicles.SpaceShip.
Hence, the earlier assignment statement:
var ship:game.vehicles.SpaceShip = new game.vehicles.SpaceShip( );
can be shortened to:
import game.vehicles.SpaceShip;
var ship:SpaceShip = new SpaceShip( );
Because of the import statement, the compiler knows we mean game.vehicles.
SpaceShip when we specify the unqualified class name SpaceShip. The import state-
ment doesn’t allow us to specify an identifier to use in place of the fully qualified ref-
erence; the alias name is always the name of the class, excluding the package
name(s). Don’t try something like this (it won’t work):
import spaceAlias = game.vehicles.SpaceShip; // Won't work!
Importing an Entire Package
The earlier import statement:
import game.vehicles.SpaceShip;
imports only the SpaceShip class, not other classes in the package. To import all the
classes in a package, use the wildcard character, *, as follows:
import packagename.*;
This wildcard syntax lets us refer to any class in packagename by its unqualified name
rather than its fully qualified name (i.e.,
packagename.ClassName).
For example, suppose the geometry package contains three classes Circle, Triangle,
and Rectangle. Rather than ...