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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CLASSES Overloading 8.4.9<br />

DISCUSSION<br />

This can happen, if a superclass is parametric, and it has two methods that were distinct in<br />

the generic declaration, but have the same signature in the particular invocation used.<br />

Otherwise, there are two possible cases:<br />

• If one of the inherited methods is not abstract, then there are two subcases:<br />

◆ If the method that is not abstract is static, a compile-time error occurs.<br />

◆ Otherwise, the method that is not abstract is considered to override, and<br />

therefore to implement, all the other methods on behalf of the class that<br />

inherits it. If the signature of the non-abstract method is not a subsignature<br />

of each of the other inherited methods an unchecked warning must be<br />

issued (unless suppressed (§9.6.1.5)). A compile-time error also occurs if<br />

the return type of the non-abstract method is not return type substitutable<br />

(§8.4.5) for each of the other inherited methods. If the return type of the<br />

non-abstract method is not a subtype of the return type of any of the other<br />

inherited methods, an unchecked warning must be issued. Moreover, a compile-time<br />

error occurs if the inherited method that is not abstract has a<br />

throws clause that conflicts (§8.4.6) with that of any other of the inherited<br />

methods.<br />

• If all the inherited methods are abstract, then the class is necessarily an<br />

abstract class and is considered to inherit all the abstract methods. A<br />

compile-time error occurs if, for any two such inherited methods, one of the<br />

methods is not return type substitutable for the other (<strong>The</strong> throws clauses do<br />

not cause errors in this case.)<br />

DRAFT<br />

<strong>The</strong>re might be several paths by which the same method declaration might be<br />

inherited from an interface. This fact causes no difficulty and never, of itself,<br />

results in a compile-time error.<br />

8.4.9 Overloading<br />

If two methods of a class (whether both declared in the same class, or both inherited<br />

by a class, or one declared and one inherited) have the same name but signatures<br />

that are not override-equivalent, then the method name is said to be<br />

overloaded. This fact causes no difficulty and never of itself results in a compile-<br />

229

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

Saved successfully!

Ooh no, something went wrong!