• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Yikes! Why does Serialization behave like that?

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings!
Here I am once again with one of my most pertinent questions, maybe this one has an obvious explanation, but I hope the motto: "There are no dumb questions" applies here as well, anyways..
If I have this:



It works. But When I assign an Object to the instance variable,



It doesn't work.
Could someone please explain to me why this is? Shouldn't the compiler know that even though there's no Object assigned to that instance variable it belongs to a class that it's not serializable? and that can be potentially dangerous...

Thanks in advance!
sincerely,
Jose
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you think the first version should not be allowed to work?

That would prevent you from implementing this:




In other words, although this might be a problem, it's not always a problem, so it makes sense to allow it. Also, what if KingKong were pointing to an instance of

 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there !
Well, Mister Ernest, Sir... yeah, I thought it shouldn't be allowed to work, but I didn't think about polymorphism. I'm sorry, I was wrong, Now I see your point. Thank you very much for the explanation. However.......
-In the first version what would be the value of KingKong after deserialization? -- null?

Thank you for your time and detailed explanation.
Best regards,
Jose
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic