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 Meaning of Type Names 6.5.5<br />

accessible (§6.6), or Id names more than one member type within Q, then a compile-time<br />

error occurs.<br />

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

package wnj.test;<br />

class Test {<br />

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

java.util.Date date =<br />

new java.util.Date(System.currentTimeMillis());<br />

System.out.println(date.toLocaleString());<br />

}<br />

}<br />

produced the following output the first time it was run:<br />

Sun Jan 21 22:56:29 1996<br />

In this example the name java.util.Date must denote a type, so we first use the<br />

procedure recursively to determine if java.util is an accessible type or a package,<br />

which it is, and then look to see if the type Date is accessible in this package.<br />

DISCUSSION<br />

Type names are distinct from type declaration specifiers (§4.3). A type name is always<br />

qualified by meas of another type name. In some cases, it is necessary to access an inner<br />

class that is a member of a parameterized type:<br />

class GenericOuter {<br />

public class Inner {<br />

T getT() { return null;}<br />

S getS() { return null;}<br />

}<br />

};<br />

GenericOuter.Inner x1 = null;<br />

Integer i = x1.getT();<br />

Double d = x1.getS();<br />

If we accessed Inner by qualifying it with a type name, as in:<br />

GenericOuter.Inner x2 = null;<br />

we would force its use as a raw type, losing type information.<br />

DRAFT<br />

133

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

Saved successfully!

Ooh no, something went wrong!