问题
I am having trouble understanding this comment from the Java serialization documentation:
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?
回答1:
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.
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.
回答2:
I haven't figured why I would need to do his.
You don't. You can't. There is no syntax for defining array classes, let alone their serialVersionUID
members.
That's also why checking it would be completely pointless. There is nothing about the class that could possibly change.
来源:https://stackoverflow.com/questions/19233303/array-classes-with-serialversionuid