gpt4 book ai didi

java - 为什么序列化需要在实现的类中提供序列版本 UID?

转载 作者:行者123 更新时间:2023-12-02 13:27:07 26 4
gpt4 key购买 nike

为什么序列化需要在实现的类中提供序列版本 UID?

最佳答案

来自the doc for java.ioSerializable :

The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long

关于java - 为什么序列化需要在实现的类中提供序列版本 UID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5576047/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com