Java Reference
In-Depth Information
an IncompatibleClassChangeError , if these methods are used by the pre-existing binaries. Such
changes are not recommended in code that has been widely distributed.
13.4.20. synchronized Methods
Adding or deleting a synchronized modifier of a method does not break compatibility with
pre-existing binaries.
13.4.21. Method and Constructor Throws
Changes to the throws clause of methods or constructors do not break compatibility with
pre-existing binaries; these clauses are checked only at compile time.
13.4.22. Method and Constructor Body
Changes to the body of a method or constructor do not break compatibility with pre-exist-
ing binaries.
The keyword final on a method does not mean that the method can be safely inlined; it
means only that the method cannot be overridden. It is still possible that a new version of
that method will be provided at link-time. Furthermore, the structure of the original pro-
gram must be preserved for purposes of reflection.
Therefore, we note that a Java compiler cannot expand a method inline at compile time.
In general we suggest that implementations use late-bound (run-time) code generation and
optimization.
13.4.23. Method and Constructor Overloading
Adding new methods or constructors that overload existing methods or constructors does
not break compatibility with pre-existing binaries. The signature to be used for each invoc-
ation was determined when these existing binaries were compiled; therefore newly added
methods or constructors will not be used, even if their signatures are both applicable and
more specific than the signature originally chosen.
While adding a new overloaded method or constructor may cause a compile-time error the
next time a class or interface is compiled because there is no method or constructor that is
most specific (ยง 15.12.2.5 ) , no such error occurs when a program is executed, because no
overload resolution is done at execution time.
Example 13.4.23-1. Adding An Overloaded Method
class Super {
static void out(float f) {
Search WWH ::




Custom Search