具有相同serialversion uid的不同类 [英] Different classes with same serialversion uid

查看:730
本文介绍了具有相同serialversion uid的不同类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的疑问。我只想知道

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

假设我在两个不同的位置(包或项目)有两个类( 100%相同的结构) ),并且我要为两者生成 serialVersionUID ,我可以放心地说,使用一个类进行序列化并使用另一个类进行反序列化是正确的吗?

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。我知道将同一个班级放在两个不同的地方并不是很好,但这不是现在的问题。

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.

感谢一吨。

推荐答案

ObjectInputStream将从输入数据中读取对象的原始完全合格的类名称,并将尝试创建该类的实例。您无法更改。不管什么serialVersionUID是序列化都将寻找原始类。

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.

这篇关于具有相同serialversion uid的不同类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆