Using the Externalizable Interface

   

The java.io.Externalizable interface can be used when an object must have complete control over how the object is serialized or externalized to be consistent with the interface name . The two methods that must be implemented are readExtenal and writeExternal. The method signatures are in Listing 22.10.

Listing 22.10 Method Signatures for the java.io.Externalizable Interface
 public void  readExternal  (ObjectInputin)                   throws IOException,                          ClassNotFoundException; public void  writeExternal  (ObjectOutputout)                    throws IOException; 

The Externalizable interface supercedes the Serializable interface. If a class implements both the Externalizable and Serializable interface, the Externalizable will be used over the Serializable to perform the externalization.When an Externalizable object is reconstructed, an instance is created using the public no-arg constructor, and then the readExternal method called. If an object is a subclass of another object, it must coordinate with the superclass to have the state inherited from the superclass.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net