具有serialVersionUID的数组类? [英] Array classes with serialVersionUID?

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

问题描述

我无法理解 Java的注释序列化文档:

数组类不能声明显式的serialVersionUID,因此它们始终具有默认的计算值,但是对于数组类,无需匹配serialVersionUID值.

Array classes cannot declare an explicit serialVersionUID, so they always have the default computed value, but the requirement for matching serialVersionUID values is waived for array classes.

也许我无法理解明显的东西,但是,我还没有弄清楚为什么我需要这样做?

Maybe I am unable to understand the obvious, however, I haven't figured why would I need to do this?

推荐答案

我认为,您的问题的答案是在

I think that the answer to your question is to read up on serialVersionUID. In particular, you often want to specify this on your classes to be able to deal with the fact that classes change over time.

您所指的注释是说您不能在阵列上设置serialVersionUID.如果是这样,并且始终需要serialVersionUID进行匹配,则您的阵列将出现严重问题,并且在序列化方面非常脆弱.为了解决这个问题,语言设计人员认为数组(反序列化)将忽略serialVersionUID,从而避免了无法定义数组的问题.

The comment that you are referring to is saying that you cannot set a serialVersionUID on arrays. If this was true, and the serialVersionUID always needed to match, then your array would have serious issues, and would be very fragile with respect to serialization. To counter this, the language designers decided that array (de)serialization would ignore the serialVersionUID, thus side-stepping the problem that it cannot be defined.

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

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