Java Programming/Keywords/transient
Appearance
From Wikibooks, open books for an open world
This is the current revision of this page, as edited by Minorax (discuss | contribs) at 11:13, 5 October 2019 (revert edits by 159.146.10.58). The present address (URL) is a permanent link to this version.
Revision as of 11:13, 5 October 2019 by Minorax (discuss | contribs) (revert edits by 159.146.10.58)
transient
is a Java keyword which marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient
keyword are not transferred; they are lost intentionally.
Syntax:
private
transient
<member-variable>; ortransient
private
<member-variable>;
For example:
Computer code
publicclass FooimplementsSerializable { privateStringsaveMe; privatetransientStringdontSaveMe; privatetransientStringpassword; //... }
See also:
- Java language specification reference: jls
- Serializable Interface. Serializable