Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a nice description in the last section of Josh Bloch's <i>Effective Java</i>, Second Edition.</p> <p>Suppose you have a class <code>A</code> that you would like to make serializable. You first declare it to implement <code>Serializable</code>. Then you use the serialization method <code>writeReplace()</code> to return a so-called "serialization proxy" that will be serialized in place of the instance of <code>A</code>. The <code>writeReplace()</code> method does not need to be public. The default serialization on <code>A</code> never gets invoked, so all of the API properites of <code>A</code> may be maintained.</p> <p>Typically, the proxy is implemented as a private static nested class that itself must implement <code>Serializable</code> (or <code>Externalizable</code> for complete control of the read/write process). Because the proxy is private, its implementation details, such as having a no-arg constructor and being mutable, will be hidden.</p> <p>The proxy stores enough of the state of the original object to write so that it can reconstitute the object on deserialization. On deserialization, the proxy uses the method <code>readResolve()</code> to return an instance of <code>A</code>. For singletons, this can be the singleton instance itself. </p> <p>I wrote up a detailed blog entry with examples, <a href="http://lingpipe-blog.com/2009/08/10/serializing-immutable-singletons-serialization-proxy/" rel="noreferrer">Serializing Immutables and Singletons with a Serialization Proxy</a>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload