BINARY COMPATIBILITY
Field Declarations
13.4.7
}
}
then these classes compile and
Test
executes to produce the output:
Test
If the method
print
in class
Point
is changed to be
public
, and then only the
Point
class is recompiled, and then executed with the previously existing binary
for
Test
then no linkage error occurs, even though it is improper, at compile time,
for a
public
method to be overridden by a
protected
method (as shown by the
fact that the class
Test
could not be recompiled using this new
Point
class unless
print were changed to be
public
.)
Allowing superclasses to change
protected
methods to be
public
without
breaking binaries of preexisting subclasses helps make Java binaries less fragile.
The alternative, where such a change would cause a linkage error, would create
additional binary incompatibilities with no apparent benefit.
13.4.7 Field Declarations
Adding a field to a class will not break compatibility with any pre existing bina
ries that are not recompiled, even in the case where a class could no longer be
recompiled because a field access previously referenced a field of a superclass
with an incompatible type. The previously compiled class with such a reference
will continue to reference the field declared in a superclass. Thus compiling and
executing the code:
class Hyper { String h = "hyper"; }
class Super extends Hyper { String s = "super"; }
class Test {
public static void main(String[] args) {
System.out.println(new Super().h);
}
}
produces the output:
hyper
Changing
Super
to be defined as:
class Super extends Hyper {
String s = "super";
int h = 0;
}
249
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved