Java Reference
In-Depth Information
closely match the types of the supplied parameters. (See Section 9.2 for more
details.)
8.4.3
Implicit Declarations
In some languages, the appearance of a name in a certain context serves to
declare the name as well. As a common example, consider the use of labels
in C. A label is introduced as an identifier followed by a colon. Unlike Pascal,
the programneed not declare the use of such labels in advance. In Fortran, the
type of an identifier for which no declaration is o
ered can be inferred from
the identifier's first letter. In Ada, a index is implicitly declared to be of the
same type as the range specifier. Moreover, a new scope is opened for the loop
so that the loop index cannot clash with an existing variable. (See Exercise 17.)
Implicit declarations are almost always introduced in a programming lan-
guage for the convenience of those who use the language rather than those
who implement it. Taking this point further, implicit declarations may ease
the task of writing programs at the expense of those who must later read them.
In any event, the compiler is responsible for supporting such features.
ff
8.4.4 Export and Import Directives
Export rules allow a programmer to specify that some local scope names are
to become visible outside that scope. This selective visibility is in contrast to
the usual block-structured scope rule, which causes local scope names to be
invisible outside the scope. Export rules are typically associated with modular-
ization features such as Ada packages, C
classes, C compilation units, and
Java classes. These language features help a programmer organize a program's
files by their functionality.
In Java, the public attribute causes the associated field or method to be
known outside its class. To prevent name clashes, each class can situate itself
in a package hierarchy through the package directive. Thus, the String class
provided in the Java core library is actually part of the java.lang package.
In contrast, all methods in C are known outside of their compilation units,
unless the static attribute is bestowed. The static methods are available
only within their compilation units.
With an export rule, each compilation unit advertises its o
++
erings. In a
large software system, the space of available global names can become polluted
and disorganized. To manage this, compilation units are typically required
to specify which names they wish to import.
ff
,theuseofa
header file includes declarations of methods and structures that can be used
by the compilation unit. In Java, the import directive specifies the classes
and packages that a compilation unit might access. Ada's use directive serves
essentially the same purpose.
In C and C
++
 
 
 
 
Search WWH ::




Custom Search