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.

15.12.2 Compile-Time Step 2: Determine Method Signature EXPRESSIONS<br />

458<br />

hold true. It follows that V[] >> U[]. Since array subtyping is covariant, it must be the case<br />

that V >> U.<br />

❖ If F has the form G, where U is a type expression<br />

that involves Tj, then:<br />

DISCUSSION<br />

✣ If A is an instance of a non-generic type, then no constraint is implied<br />

on Tj. In this case (once again restricting the analysis to the unary case), we have the constraint<br />

A >> F = G. A must be a supertype of the generic type G. However, since A is not a<br />

parameterized type, it cannot depend upon the type argument U in any way. It is a supertype<br />

of G for every X that is a valid type argument to G. No meaningful constraint on U<br />

can be derived from A.<br />

DISCUSSION<br />

✣ If A is an invocation of a generic type declaration H, where H is either G<br />

or superclass or superinterface of G, then:<br />

✦ If H ≠<br />

G,<br />

then let S1, ..., Sn be the formal type parameters of G, and let<br />

H be the unique invocation of H that is a supertype of<br />

G, and let V = H[Sk =U]. <strong>The</strong>n, if V:>F<br />

this algorithm is applied recursively to the constraint A >> V.<br />

DRAFT<br />

Our goal here is to simplify the relationship between A and F. We aim to recursively invoke<br />

the algorithm on a simpler case, where the actual type argument is known to be an invocation<br />

of the same generic type declaration as the formal.<br />

Let’s consider the case where both H and G have only a single type argument. Since<br />

we have the constraint A = H >> F = G, where H is distinct from G, it must be the<br />

case that H is some proper superclass or superinterface of G. <strong>The</strong>re must be a (non-wildcard)<br />

invocation of H that is a supertype of F = G. Call this invocation V.<br />

If we replace F by V in the constraint, we will have accomplished the goal of relating<br />

two invocations of the same generic (as it happens, H).<br />

How do we compute V? <strong>The</strong> declaration of G must introduce a formal type parameter<br />

S, and there must be some (non-wildcard) invocation of H, H, that is a supertype of

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

Saved successfully!

Ooh no, something went wrong!