If you think about how serialization works, you can see that the version UID must be stored with the serialized data. Otherwise, how could the deserialization process tell whether the data was originally produced by the same version of the class?
posted 10 months ago
yep I know, but how you can explain what static members are not stored, however, UID is stored !!!
I find it's better not to make assumptions about how things are implemented. However, it's true that if you serialize an object using serialVersionUID = 42 and then try to deserialize it using serialVersionUID = 86, an exception will occur. That means the deserialization process knows what serialVersionUID was at the time of serialization.
This is what you need to know about serialVersionUID.
Now, the only way I can see to implement that rule is by storing the serialVersionUID in every serialized object. But Java implementers are very smart people and for all I know they have implemented that rule in a very smart way which I didn't think of. So nitpicking about whether the serialVersionUID is actually written out is, to me, counterproductive. Whether the documentation actually says that serialVersionUID is actually stored, I don't know.
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java