JVM Knowledge

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 six categories: PackageName, TypeName, ExpressionName, MethodName, PackageOrTypeName, or AmbiguousName.
  • 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).
PackageName:
  Identifier
  PackageName . Identifier

TypeName:
  Identifier
  PackageOrTypeName . Identifier

PackageOrTypeName:
  Identifier
  PackageOrTypeName . Identifier

ExpressionName:
  Identifier
  AmbiguousName . Identifier

MethodName:
  Identifier

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: