Java Reference
In-Depth Information
type denoted by
T
, then this
AmbiguousName
is reclassified as a
TypeName
.
♦ Otherwise, a compile-time error occurs.
Example 6.5.2-1. Reclassification of Contextually Ambiguous Names
Consider the following contrived “library code”:
package org.rpgpoet;
import java.util.Random;
public interface Music { Random[] wizards = new Random[4]; }
and then consider this example code in another package:
package bazola;
class Gabriel {
static int n = org.rpgpoet.Music.wizards.length;
}
First of all, the name
org.rpgpoet.Music.wizards.length
is classified as an
ExpressionName
because it functions as a
PostfixExpression
. Therefore, each of the names:
org.rpgpoet.Music.wizards
org.rpgpoet.Music
org.rpgpoet
org
is initially classified as an
AmbiguousName
. These are then reclassified:
• The simple name
org
is reclassified as a
PackageName
(since there is no
variable or type named org in scope).
• Next, assuming that there is no class or interface named
rpgpoet
in any com-
pilation unit of package
org
(and we know that there is no such class or inter-
face because package
org
has a subpackage named
rpgpoet
), the qualified
name
org.rpgpoet
is reclassified as a
PackageName
.
named
Music
, the qualified name
org.rpgpoet.Music
is reclassified as a
TypeName
.
• Finally, because the name
org.rpgpoet.Music
is a
TypeName
, the qualified name
org.rpgpoet.Music.wizards
is reclassified as an
ExpressionName
.