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 Interfacepublic 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. |