Java Reference
In-Depth Information
This type of import statement is officially named a single-type-import declara-
tion statement.
For brevity's sake, a class can identify all of the classes in a package by using the
asterisk (*) wild card instead of listing each class name. This statement instructs the
compiler to import all the classes in java4cobol.message as they are needed, in-
cluding ErrorMsg :
package general_ledger;
import java4cobol.message.*;
This type of import statement is officially named a type-import-on-demand de-
claration statement.
Although the import statement behaves in a manner similar to the COBOL
COPY statement, it is really quite different. No code is actually imported, just the
public class definitions. Significantly, the import statement tells the compiler to im-
port the class file (the compiler output) and not the Java file (the source file). It is
more of an aid to the compiler than it is a technique to copy code from another class.
Now that the Accounts class contains this import statement, it can refer to any
class in the java4cobol.message package using only the class name. You do not
need to use the full package.classname syntax.
N AME C OLLISIONS
When using the wild card import statement, it is possible for a class to have the
same name in two separate packages, or for your program to create a name that col-
lides with a name in an imported package. In this case, the package name can be
used to uniquely identify a class in a package:
package general_ledger;
import java4cobol.messages.*;
public class Accounts {
// Create a String object with the same name as the class ErrorMsg.
String ErrorMsg;
public String accountID;
public BigDecimal accountBalance;
...
Search WWH ::




Custom Search