Java Reference
In-Depth Information
tion
when the class of the object being restored cannot be found.
(
java.io.ObjectInput
is a subinterface of
DataInput
and is imple-
mented by
ObjectInputStream
.)
If a class implements
Externalizable
, its
writeExternal()
method is re-
sponsibleforsavingallfieldvaluesthataretobesaved.Also,its
readExternal()
method is responsible for restoring all saved field values and in the order they were
saved.
you how to take advantage of externalization.
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
class Employee implements Externalizable
{
private String name;
private int age;
public
Employee()
{
System.out.println("Employee() called");
}
Employee(String name, int age)
{
this.name = name;
this.age = age;
}
String getName() { return name; }
int getAge() { return age; }
@Override
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException
{
System.out.println("readExternal() called");