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.

CLASSES Method Signature 8.4.2<br />

Two method or constructor declarations M and N have the same argument types<br />

if all of the following conditions hold:<br />

• <strong>The</strong>y have the same number of formal parameters (possibly zero)<br />

• <strong>The</strong>y have the same number of type parameters (possibly zero)<br />

• Let be the formal type parameters of M and let be<br />

the formal type parameters of N. After renaming each occurrence of a Bi in N’s<br />

type to Ai the bounds of corresponding type variables and the argument types<br />

of M and N are the same.<br />

<strong>The</strong> signature of a method m1 is a subsignature of the signature of a method<br />

m2 if either<br />

◆ m2 has the same signature as m1, or<br />

◆ the signature of m1 is the same as the erasure of the signature of m2.<br />

DISCUSSION<br />

<strong>The</strong> notion of subsignature defined here is designed to express a relationship between two<br />

methods whose signatures are not identical, but in which one may override the other.<br />

Specifically, it allows a method whose signature does not use generic types to override<br />

any generified version of that method. This is important so that library designers may freely<br />

generify methods independently of clients that define subclasses or subinterfaces of the<br />

library.<br />

Consider the example:<br />

class CollectionConverter {<br />

List toList(Collection c) {...}<br />

}<br />

class Overrider extends CollectionConverter{<br />

List toList(Collection c) {...}<br />

}<br />

Now, assume this code was written before the introduction of genericity, and now the<br />

author of class CollectionConverter decides to generify the code, thus:<br />

class CollectionConverter {<br />

List toList(Collection c) {...}<br />

}<br />

Without special dispensation, Overrider.toList() would no longer override CollectionConverter.toList().<br />

Instead, the code would be illegal. This would significantly<br />

inhibit the use of genericity, since library writers would hesitate to migrate existing code.<br />

DRAFT<br />

213

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

Saved successfully!

Ooh no, something went wrong!