Java Reference
In-Depth Information
If a new method of type X with the same signature and return type as m is added to a sub-
class of S that is a superclass of T or T itself, then a linkage error may occur. Such a link-
age error will occur only if, in addition to the above, either one of the following conditions
hold:
• The new method is less accessible than the old one.
• The new method is a static (respectively instance) method.
Deleting a method or constructor from a class may break compatibility with any pre-exist-
ing binary that referenced this method or constructor; a NoSuchMethodError may be thrown
when such a reference from a pre-existing binary is linked. Such an error will occur only if
no method with a matching signature and return type is declared in a superclass.
If the source code for a non-inner class contains no declared constructors, the Java compiler
automatically supplies a default constructor with no parameters (§ 8.8.9 ). Adding one or
more constructor declarations to the source code of such a class will prevent this default
constructor from being supplied automatically, effectively deleting a constructor, unless
one of the new constructors also has no parameters, thus replacing the default constructor.
The automatically supplied constructor with no parameters is given the same access modi-
fier as the class of its declaration, so any replacement should have as much or more access
if compatibility with pre-existing binaries is to be preserved.
13.4.13. Method and Constructor Type Parameters
Adding or removing a type parameter of a method or constructor does not, in itself, have
any implications for binary compatibility.
If such a type parameter is used in the type of the method or constructor, that may have the
normal implications of changing the aforementioned type.
Renaming a type parameter of a method or constructor has no effect with respect to pre-ex-
isting binaries.
Changing the first bound of a type parameter of a method or constructor may change the
erasure (§ 4.6 ) of any member that uses that type parameter in its own type, and this may
affect binary compatibility. Specifically:
• If the type parameter is used as the type of a field, the effect is as if the field was
removed and a field with the same name, whose type is the new erasure of the type
variable, was added.
• If the type parameter is used as the type of any formal parameter of a method, but
not as the return type, the effect is as if that method were removed, and replaced
Search WWH ::




Custom Search