What happens if we serialize and deserialize two objects which references to each other?
Posted
by
Seregwethrin
on Programmers
See other posts from Programmers
or by Seregwethrin
Published on 2012-05-31T19:54:55Z
Indexed on
2012/05/31
22:50 UTC
Read the original article
Hit count: 166
To make it more clear, this is a quick example:
class A implements Serializable { public B b; }
class B implements Serializable { public A a; }
A a = new A();
B b = new B();
a.b = b;
b.a = a;
So what happens if we serialize a and b objects into a file and deserialize from that file?
I thought we get 4 objects, 2 of each. Identical objects but different instances.
But I'm not sure if there's anything else or is it right or wrong.
If any technology needed to answer, please think based on Java.
Thank you.
© Programmers or respective owner