Skip to main content

Posts

Showing posts with the label final

Can 'transient' variables be declared as 'final' or 'static'?

Java's serialization provides an elegant, and easy to use mechanism for making an object's state persistent. While controlling object serialization, we might have a particular object data member that we do not want the serialization mechanism to save. The modifier transient can be applied to field members of a class to turn off serialization on these field members. Every field marked as transient will not be serialized. You use the transient keyword to indicate to the Java virtual machine that the transient variable is not part of the persistent state of an object. The transient modifier applies to variables only. Like other variable modifiers in the Java system, you use transient in a class or instance variable declaration like this: class TransientExample { transient int hobo; . . . } This statement declares an integer variable named hobo that is not part of the persistent state of the TransientExample class.