What is the reserved keyword transient used for?

Byron Tymvios

The transient keyword is used to tell Java that the specified variable should not be persisted when serializing an object. All nonserializable fields as well as fields that you do not want to persist should be marked as transient. When an object is serialized the fields marked as transient will not have their data persisted, therefore when the object is deserialized these variables will have no data.

It is used as follows when declaring variables:

private transient String doNotPersist = "Some String";

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact