Java Reference
In-Depth Information
This defines five different overloads of the method m . Replacing each
method's signature by its erasure, we would get the following corres-
ponding set of methods:
void m(int x) {}
void m(Object t) {}
void m(String s) {}
void m(Number n) {}
void m(SingleLinkQueue q) {}
It is an error for a class or interface to declare two methods with the
same name and the same signature erasure. Consequently, trying to
define any of the following versions of m in Base would be an error:
void m(Object o) {}
void m(Number n) {}
<G extends String> void m(G g) {}
void m(SingleLinkQueue<Object> q) {}
In each case, the erasure of the signature matches the erasure of one
of the other signatures.
A method in a subtype potentially overrides an accessible method in a
super type if the two methods have the same name and have override-
equivalent signatures. We say "potentially overrides" because there is
an additional requirement to be met: The signature of the subclass
method must be the same as that of the superclass method, or it must
be the same as the erasure of the signature of the superclass method.
This constraint makes overriding a "one-way street": A method without
generic types can override a method with generic types, but not the oth-
er way around. You are allowed to do this so that you can generify an
existing class without breaking previously existing subclasses that over-
rode methods.
 
Search WWH ::




Custom Search