what is meant by giving a variable within a class variable a transient attribute?
1
Expert's answer
2016-11-03T16:16:09-0400
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, or saved on a hard drive 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.
In an object you may have information that you don't want to serialize (a stored password or any private information), or perhaps it doesn't make sense to serialize (a reference to a parent factory object). Marking these as 'transient' means the serialization mechanism will ignore these fields.
Comments
Leave a comment