Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Questions on serializable and deserializable understanding

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its okay for a class to implement serializable even if its superclass doesn't. However, when
you deserialize such an object, the non serializable superclass must run its constructor. Constructors
dont run on deserialized class that implement serializable.

Why the constructors dont run on deserialized class that implements serializable?
 
Ranch Hand
Posts: 72
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

smiling sun wrote:Its okay for a class to implement serializable even if its superclass doesn't. However, when
you deserialize such an object, the non serializable superclass must run its constructor. Constructors
dont run on deserialized class that implement serializable.

Why the constructors dont run on deserialized class that implements serializable?



Because the whole point of serialization is to save a certain object's state. By state we mean the state of the object's instance variables.
If the constructor runs, chances are those instance variables are going to be reset back to default values and you end up with a new object, rather than the one you have serialized.

Let me know if you have more questions.
 
sam ray
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks...Boris, Thanks for the explanation.
 
Boris Mechkov
Ranch Hand
Posts: 72
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sam ray wrote:Thanks...Boris, Thanks for the explanation.


No problem man.
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic