10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6.5 Determining the Meaning of a Name NAMES<br />

126<br />

<strong>The</strong> example:<br />

class Test {<br />

public static void main(String[] args) {<br />

int[] ia = new int[3];<br />

int[] ib = new int[6];<br />

System.out.println(ia.getClass() == ib.getClass());<br />

System.out.println("ia has length=" + ia.length);<br />

}<br />

}<br />

produces the output:<br />

true<br />

ia has length=3<br />

This example uses the method getClass inherited from class Object and the<br />

field length. <strong>The</strong> result of the comparison of the Class objects in the first<br />

println demonstrates that all arrays whose components are of type int are<br />

instances of the same array type, which is int[].<br />

6.5 Determining the Meaning of a Name<br />

<strong>The</strong> meaning of a name depends on the context in which it is used. <strong>The</strong> determination<br />

of the meaning of a name requires three steps. First, context causes a name<br />

syntactically to fall into one of six categories: PackageName, TypeName, ExpressionName,<br />

MethodName, PackageOrTypeName, or AmbiguousName. Second, a<br />

name that is initially classified by its context as an AmbiguousName or as a PackageOrTypeName<br />

is then reclassified to be a PackageName, TypeName, orExpressionName.<br />

<strong>Third</strong>, the resulting category then dictates the final determination of<br />

the meaning of the name (or a compilation error if the name has no meaning).<br />

PackageName:<br />

Identifier<br />

PackageName . Identifier<br />

TypeName:<br />

Identifier<br />

PackageOrTypeName . Identifier<br />

ExpressionName:<br />

Identifier<br />

AmbiguousName . Identifier<br />

DRAFT

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!