• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Transient variables and serialization

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

From Kathy and Sierra, from the Chapter Objects and Collections: The hashCode() Contract: i gather the following:

Suppose an object having 2 variables x and y is serialized. x is transient and y is not. While serializing the object, the value of x = 10, y = 9. After we deserialize this object, the value of the transient variable reset to the default value. So will x be = 0 after desrialization? Why does this happen?

Thanks
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By making a variable transient, you indicate that the variable does not add to the object's state and hence should not be saved/serialized.
Now when restoring the same object, transient variable value is not available and it gets the same treatment as class variables get during initialization and gets assigned to default value.


Hope this helps
 
Natalie Ap
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amit Ghorpade wrote:By making a variable transient, you indicate that the variable does not add to the object's state and hence should not be saved/serialized.
Now when restoring the same object, transient variable value is not available and it gets the same treatment as class variables get during initialization and gets assigned to default value.


Hope this helps



Thanks! I understood the concept of transient variables now!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic