• Post Reply Bookmark Topic Watch Topic
  • New Topic

Rules of Serializaton  RSS feed

 
Simeon Cherniy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I have a question.
I have the class
public class Test implements Serializable
{
public TestTwoClass classTwo = new TestTwoClass();
public int i;
...
}

After serialization and deserialization will the variable 'classTwo' reffer to the object TestTwoClass?

Are there any requirements to the TestTwoClass?

If TestTwoClass is not serializable, what value will the variable 'classTwo' has?

Thanks!

[ June 04, 2007: Message edited by: Simeon Cherniy ]
[ June 04, 2007: Message edited by: Simeon Cherniy ]
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If class TestTwoClass implements Serializable it would get the value TestTwoClass's var had when the object is being serialized. If not it would throw an Exception. You can provide code for custom serialization/deserialization.
[ June 04, 2007: Message edited by: Anupam Sinha ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anupam Sinha:
If class TestTwoClass implements Serializable it would get the value TestTwoClass's var had when the object is being serialized.


To further clarify: it would reference a *new* deserialized instance, *not* the original instance before serialization.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!