Im reading the incredible book “a programmer's guide to java scjp certification” for jdk6 and theres a section about generic overriding. On it is described subsignature and override-equivalent and describes some examples of override-equivalent that I quote:
Given the following three generic method declarations in a class:
static <T> void merge (MyStack<T> s1, MyStack<T> s2) { /*...*/ }
static <T> void merge (MyStack<T> s1, MyStack<? extends T> s2) { /*...*/ }
static <T> void merge (MyStack<T> s1, MyStack<? super T> s2) { /*...*/ }
After erasure, the signature of all three methods is:
merge(MyStack, MyStack)
i.e., the signatures of the methods are override-equivalent, hence these methods are not overloaded.
Im not totally agree that these methods are override-equivalent , in fact i think the methods have a “name clash by erasure” but none is subsignature of the other one… possibly im wrong so i want some light on this.
The definitions of subsignature makes me think that they arent subsignatures between them.
In JSL 6 #8.4.2 Method Signature (http://docs.oracle.com/javase/specs/jls/se6/html/classes.html#8.4.2)
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
<A1,...,An>
be the formal type parameters of M and let<B1,...,Bn>
be the formal type parameters of N. After renaming each occurrence of a Bi in N's type to Ai the bounds of corresponding type variables and the argument types of M and N are the same.The signature of a method m1 is a subsignature of the signature of a method m2 if either m2 has the same signature as m1, or the signature of m1 is the same as the erasure of the signature of m2
...
Two method signatures m1 and m2 are override-equivalent iff either m1 is a subsignature of m2 or m2 is a subsignature of m1.
In JSL 8 # 8.4.2. Method Signature (http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2)
Two methods or constructors, M and N, have the same signature if they have the same name, the same type parameters (if any) (§8.4.4), and, after adapting the formal parameter types of N to the the type parameters of M, the same formal parameter types.
The signature of a method m1 is a subsignature of the signature of a method m2 if either:
m2 has the same signature as m1, or
the signature of m1 is the same as the erasure of the signature of m2.
Two method signatures m1 and m2 are override-equivalent iff either m1 is a subsignature of m2 or m2 is a subsignature of m1.
EDIT 1
To put it simple, my doubt is that from the subsignature definition in respect to erasure i understand that "one signature without erasure is equal to the erasure from the other signature".. and not that "both signatures after erasure are equal" .. its subtle but important (by the way, the override-equivalent definition is based on subsignature definition, thats why i ask in terms of subsignatures)