What is a Java backreference?

Especially in the context of the readunshared () method of objectinputstream,

I came across the word here

reference resources: https://docs.oracle.com/javase/7/docs/api/java/io/ObjectInputStream.html#readUnshared ()

Solution

When serializing an object using objectoutputstream, the stream "remembers" the object it has written to When it has to write the same object again, it will not write the whole object again, but will write an identifier called "backward reference"

Receiving objectinputstream will also track the received objects and return the same objects it previously read when reading the post reference

As described in answer by corona, this is – among other things – used to serialize objects pointing to each other and to ensure that identity equality in one JVM is preserved when serializing to another JVM

The method readunshared (and its counter part writeunshared) is used to get rid of this behavior: it ensures that the object read (written) will be unique (and will not be reused as a backward reference) This is quite advanced. I don't remember seeing or using it, but then again, I rarely see the use of serialization

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>