Thursday, April 19, 2001 02:19 PM
is a protected
method in ObjectOutputStream
, and as such it
is only callable within ObjectOutputStream
or within subclasses of ObjectOutputStream
is probably not what you want to be using.
The proper way to designate and use replacement objects
is by defining the Object writeReplace()
method in your serializable class. Since this method is part
of each serializable class, it is implicit which object is being
replaced, while the replacement object is the return value of this
method. The replacement object must also be serializable
and define (if desired) a Object readResolve() method.
The return value of this read method can be used to restore the
The object streams for reading and writing know nothing about
which objects are replaced, and by what other objects they are
replaced. The output stream for instance automatically
invokes writeReplace() on every serializable object
that has that method defined, and simply writes the return
value to the stream.
This process is explained in great detail in the Serialization specification.