The meaning of a name depends on the context in which it is used. The determination of the meaning of a name requires three steps:
-
First, context causes a name syntactically to fall into one of seven categories: ModuleName, PackageName, TypeName, ExpressionName, MethodName, PackageOrTypeName, or AmbiguousName.
TypeName and MethodName are less expressive than the other five categories, because they are denoted with TypeIdentifier and UnqualifiedMethodIdentifier, respectively. The former excludes the character sequences
varandyield(§3.8), and the latter excludes the character sequenceyield. -
Second, a name that is initially classified by its context as an AmbiguousName or as a PackageOrTypeName is then reclassified to be a PackageName, TypeName, or ExpressionName.
-
Third, the resulting category then dictates the final determination of the meaning of the name (or a compile-time error if the name has no meaning).
ModuleName:
Identifier
ModuleName . Identifier
PackageName:
Identifier
PackageName . Identifier
TypeName:
TypeIdentifier
PackageOrTypeName . TypeIdentifier
PackageOrTypeName:
Identifier
PackageOrTypeName . Identifier
ExpressionName:
Identifier
AmbiguousName . Identifier
MethodName:
UnqualifiedMethodIdentifier
AmbiguousName:
Identifier
AmbiguousName . Identifier
The use of context helps to minimize name conflicts between entities of different kinds. Such conflicts will be rare if the naming conventions described in §6.1 are followed. Nevertheless, conflicts may arise unintentionally as types developed by different programmers or different organizations evolve. For example, types, methods, and fields may have the same name. It is always possible to distinguish between a method and a field with the same name, since the context of a use always tells whether a method is intended.
Sections: