13.4.8
final
Fields and Constants
BINARY COMPATIBILITY
recompiling
Hyper
 and
Super
, and executing the resulting new binaries with the
old binary of
Test
 produces the output:
hyper
The field
h
 of
Hyper
 is output by the original binary of
main
 no matter what type
field
h
 is declared in
Super
. While this may seem surprising at first, it serves to
reduce the number of incompatibilities that occur at run time. (In an ideal world,
all source files that needed recompilation would be recompiled whenever any one
of them changed, eliminating such surprises. But such a mass recompilation is
often impractical or impossible, especially in the Internet. And, as was previously
noted, such recompilation would sometimes require further changes to the source
code.)
Deleting a field from a class will break compatibility with any pre existing
binaries that reference this field, and a
NoSuchFieldError
 will be thrown when
such a reference from a pre existing binary is linked. Only
private
 fields may be
safely deleted from a widely distributed class.
13.4.8
final
Fields and Constants
If a field that was not
final
 is changed to be
final
, then it can break compatibil 
ity with pre existing binaries that attempt to assign new values to the field. For
example, if the program:
class Super { static char s; }
class Test extends Super {
public static void main(String[] args) {
s =  a ;
System.out.println(s);
}
}
is compiled and executed, it produces the output:
a
Suppose that a new version of class
Super
 is produced:
class Super { static char s; }
If
Super
 is recompiled but not
Test
, then running the new binary with the exist 
ing binary of
Test
 results in a
IncompatibleClassChangeError
. (In certain
250






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

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