Local database reading edition

What is Transient Modifier and When to use?

Reconstructed from database records, not a captured original forum layout. Dates and display names are retained as recorded; timezone and real-world identity are not inferred. Historical advice, contact details and offers are not current. Original markup is shown as inert text.

Forum index · Java - Tips Of The Day

Opening post

Asha · 2001-04-04 18:16:34

One of the less commonly used keywords in the Java language is transient.It indicates a field that is not a part of the object's persistent state. Hence, declaring a variable as transient prevents it from being serialized. If the some object variable does not need to be serialized, you can change the class that uses to: <pre id=code><font face=courier size=2 id=code> public class TestSerializable implements Serializable { public String s = &quot;Hello&quot;; public transient NonSerializableObject o = new NonSerializableObject(s); ... } </font id=code></pre id=code> The transient modifier is now used to qualify the object o. As a result, when the writeObject() method is used for an object of the type TestSerializable, the object o is not saved along with the object. If you need to preserve the state of the object o, then you will have to customize how you serialize objects of type Serializable. Asha Balasubramanyan http://www.ammu.org Edited by - asha on April 04 2001 6:17:12 PM

Source notes

MyCommunity/nandighosha.org.zip!/forum/tools/snitz_forums_2000.mdb
Table: FORUM_TOPICS + FORUM_REPLY · record IDs: 77