title: What is the meaning of reference sharing in Serialization? How Enums are Serialized?
body: <p>I am reading through <a href="http://docs.oracle.com/javase/6/docs/api/java/io/ObjectOutputStream.html#defaultWriteObject%28%29" rel="nofollow noreferrer">ObjectOutputStream Documentation</a> and reading about Serialization and i have some confusions. It states that</p>
  <blockquote>
  <p>Multiple references to a single object are encoded using a reference
  sharing mechanism so that graphs of objects can be restored to the
  same shape as when the original was written.</p>
  </blockquote>
  <p>What is the meaning of refence sharing mechanism? It also states that</p>
  <blockquote>
  <p>Enum constants are serialized differently than ordinary serializable
  or externalizable objects. The serialized form of an enum constant
  consists solely of its name; field values of the  constant are not
  transmitted. To serialize an enum constant, ObjectOutputStream writes
  the string returned by the constant's name methodLike other
  serializable or externalizable objects, enum constants can function as
  the targets of back references appearing subsequently in the
  serialization stream.</p>
  </blockquote>
  <p>One reason i can think of is, as Enum fields are constants, so they won't be serialized.
  Then how exactly if we have the need to serialize an Enum? Another thing, if the state can't
  be serialized, why doesn't the compiler restrict us for serializing an Enum? What is the
  meaning, that enum constants can function as the targets  of back references?</p>
  <p>Please help in clarifying this doubt. Thanks.</p>