• Post Reply Bookmark Topic Watch Topic
  • New Topic

Yikes! Why does Serialization behave like that?  RSS feed

 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!