Java Reference
In-Depth Information
8.4.2. Method Signature
Two methods have the same signature if they have the same name and argument types.
Two method or constructor declarations M and N have the same argument types if all of the
following conditions hold:
• They have the same number of formal parameters (possibly zero)
• They have the same number of type parameters (possibly zero)
• Let A 1 , ..., A n be the type parameters of M and let B 1 , ..., B n be the type parameters
of N . After renaming each occurrence of a B i in N 's type to A i , the bounds of cor-
responding type variables are the same, and the formal parameter types of M and N
are the same.
The signature of a method m 1 is a subsignature of the signature of a method m 2 if either:
m 2 has the same signature as m 1 , or
• the signature of m 1 is the same as the erasure (§ 4.6 ) of the signature of m 2 .
Two method signatures m 1 and m 2 are override-equivalent iff either m 1 is a subsignature of
m 2 or m 2 is a subsignature of m 1 .
It is a compile-time error to declare two methods with override-equivalent signatures in a
class.
Example 8.4.2-1. Override-Equivalent Signatures
Click here to view code image
class Point {
int x, y;
abstract void move(int dx, int dy);
void move(int dx, int dy) { x += dx; y += dy; }
}
This program causes a compile-time error because it declares two move methods with
the same (and hence, override-equivalent) signature. This is an error even though one
of the declarations is abstract .
The notion of subsignature is designed to express a relationship between two methods
whose signatures are not identical, but in which one may override the other. Spe-
cifically, it allows a method whose signature does not use generic types to override
any generified version of that method. This is important so that library designers may
Search WWH ::




Custom Search