Different classes with same serialversion uid

狂风中的少年 提交于 2019-12-14 02:15:33

问题


I am having a strange doubt. All I want to know is,

suppose if I have two classes, (100% same structure) in two different locations (packages or projects), and I take care of generating the same serialVersionUID for both, can I safely say it's right to serialize using one class and de-serialize using another?

P.S. I understand that it's not good to keep the same class in two separate places, but that's not the question right now.

Thanks a ton.


回答1:


ObjectInputStream will read the original fully qualified class name of the object from input data and will try to create an instance of this class. You cannot change that. Serialization will be looking for the original class no matter what serialVersionUID is.



来源:https://stackoverflow.com/questions/16683630/different-classes-with-same-serialversion-uid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!