Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>what will be the value of sc.y after ois.readObject ?</p> </blockquote> <p><code>Someclass.y</code> will be the "default value". In this case, since it's an object, it will be <code>null</code>.</p> <blockquote> <p>What does it mean that transient fields are ignored?</p> </blockquote> <p>They're not serialised - they're skipped. From the <a href="http://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#4539" rel="nofollow">Java Object Serialisation Specification</a>:</p> <blockquote> <p>A Serializable class must do the following:</p> <ul> <li>Implement the java.io.Serializable interface</li> <li>Identify the fields that should be serializable (Use the <code>serialPersistentFields</code> member to explicitly declare them serializable or <strong>use the <code>transient</code> keyword to denote nonserializable fields</strong>.) </li> </ul> </blockquote> <p>... and ...</p> <blockquote> <p>The easiest technique is to mark fields that contain sensitive data as <code>private transient</code>. <strong>Transient fields are not persistent and will not be saved by any persistence mechanism. Marking the field will prevent the state from appearing in the stream and from being restored during deserialization</strong>. Since writing and reading (of private fields) cannot be superseded outside of the class, the transient fields of the class are safe.</p> </blockquote> <p>And your next question:</p> <blockquote> <p>And how can they be read from the stream if they are transient</p> </blockquote> <p>They're not in the stream - so, actually, they're not read. As mentioned above, the end up as the 'default value' for that type (<code>null</code> for objects, <code>0</code>/<code>false</code> for primitives).</p> <blockquote> <p>"Fields declared as transient or static are ignored by the deserialization process."</p> </blockquote> <p>For the most common case, they're ignored by the <em>serialisation</em> process - and because of that, they're not in the stream, and won't be deserialised. However, if you changed the class subsequent to serialising the object so that a field that used to be serialised is now marked as transient, then the deserialisation process will ignore that value when it finds it in the stream.</p>
 

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