本文介绍了安卓:如果我添加的serialVersionUID老序列化对象会发生什么情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你把一个旧的序列化对象,从未有过的serialVersionUID明确规定,并添加的serialVersionUID到该对象会发生什么情况?在我看来,下一次该应用程序是由最终用户更新,它会尝试从光盘反序列化数据,找出了serialVersionUID的不匹配,覆盖从服务器/ DB新的数据/数据​​不管以后你再罚款。我是正确的这一假设?是否有进一步的问题,我应该警惕在做这个?

 私有类X实现Serializable {...

私有静态最后长的serialVersionUID = 0L;
 

解决方案
  1. 如果你给它显示运行的类用serialver 工具,因为它现在是,什么也没有发生相同的值。
  2. 如果你给它一个不同的值,现有的串行数据流,包括该类将失败与 InvalidClassException 进一步deserializations。

正确的。

只有当它真的不匹配。如果你按照上面的建议,它将匹配。

不正确的。见上面。

没有。

没有。

What happens if you take an old serializable object that never had serialVersionUID explicitly specified, and add serialVersionUID to that object? It seems to me that the next time the app was updated by endusers it would try to deserialize data from disc, find out that the serialVersionUID didn't match, overwrite the data with new data from the server/db/whatever and after that you're fine. Am I correct in this assumption? Are there further issues I should be wary of in doing this?

private class X implements serializable {...

private static final long serialVersionUID = 0L;
解决方案
  1. If you give it the same value that is shown by running the serialver tool on the class as it is now, nothing happens.
  2. If you give it a different value, further deserializations of existing serial streams including that class will fail with an InvalidClassException.

Correct.

Only if it really didn't match. If you follow the advice above, it will match.

Incorrect. See above.

No.

No.

这篇关于安卓:如果我添加的serialVersionUID老序列化对象会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 11:04