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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

NAMES Shadowing Declarations 6.3.1<br />

<strong>The</strong>se rules imply that declarations of class and interface types need not<br />

appear before uses of the types.<br />

In the example:<br />

package points;<br />

class Point {<br />

int x, y;<br />

PointList list;<br />

Point next;<br />

}<br />

class PointList {<br />

Point first;<br />

}<br />

the use of PointList in class Point is correct, because the scope of the class<br />

declaration PointList includes both class Point and class PointList, as well<br />

as any other type declarations in other compilation units of package points.<br />

6.3.1 Shadowing Declarations<br />

Some declarations may be shadowed in part of their scope by another declaration<br />

of the same name, in which case a simple name cannot be used to refer to the<br />

declared entity.<br />

A declaration d of a type named n shadows the declarations of any other types<br />

named n that are in scope at the point where d occurs throughout the scope of d.<br />

A declaration d of a field, local variable, method parameter, constructor<br />

parameter or exception handler parameter named n shadows the declarations of<br />

any other fields, local variables, method parameters, constructor parameters or<br />

exception handler parameters named n that are in scope at the point where d<br />

occurs throughout the scope of d.<br />

A declaration d of a method named n shadows the declarations of any other<br />

methods named n that are in an enclosing scope at the point where d occurs<br />

throughout the scope of d.<br />

A package declaration never shadows any other declaration.<br />

A single-type-import declaration d in a compilation unit c of package p that<br />

imports a type named n shadows the declarations of:<br />

• any top level type named n declared in another compilation unit of p.<br />

• any type named n imported by a type-import-on-demand declaration in c.<br />

DRAFT<br />

• any type named n imported by a static-import-on-demand declaration in c.<br />

throughout c.<br />

119

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

Saved successfully!

Ooh no, something went wrong!