问题
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