Does Java Serialization work for cyclic references?

前端 未结 4 1074
误落风尘
误落风尘 2021-01-01 18:16

For example: Object A contains Object B that contains Object C that contains Object A.

Will Object A serialize properly?

Comment #9 here indicates that it d

4条回答
  •  生来不讨喜
    2021-01-01 18:53

    Yes, the default Java serialization works for cyclic references. When you serialize object C, the field will contain a backreference to the already-serialized object A instead of serializing it again.

提交回复
热议问题