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.

4.8 Raw Types TYPES, VALUES, AND VARIABLES<br />

58<br />

More precisely, a raw type is define to be either:<br />

• <strong>The</strong> name of a generic type declaration used without any accompanying<br />

actual type parameters.<br />

• Any non-static type member of a raw type R that is not inherited from a superclass<br />

or superinterface of R.<br />

DISCUSSION<br />

<strong>The</strong> latter point may not be immediately self evident. Presenting for your consideration,<br />

then, the following example:<br />

class Outer{<br />

T t;<br />

class Inner {<br />

T setOuterT(T t1) {t = t1;return t;}<br />

}<br />

}<br />

<strong>The</strong> type of the member(s) of Inner depends on the type parameter of Outer. IfOuter is<br />

raw, Inner must be treated as raw as well, as their is no valid binding for T.<br />

This rule applies only to type members that are not inherited. Inherited type members<br />

that depend on type variables will be inherited as raw types as a consequence of the rule<br />

that the supertypes of a raw type are erased, described later in this section.<br />

DISCUSSION<br />

Another implication of the rules above is that a generic inner class of a raw type can itself<br />

only be used as a raw type:<br />

class Outer{<br />

class Inner {<br />

S s;<br />

}<br />

}<br />

it is not possible to access Inner as partially raw type (a "rare" type)<br />

Outer.Inner x = null; // illegal<br />

Double d = x.s;<br />

because Outer itself is raw, so are all its inner classes, including Inner, and so it is<br />

not possible to pass any type parameters to it.<br />

DRAFT

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

Saved successfully!

Ooh no, something went wrong!