[英]Why serialVersionUID is of type long for Serializable classes
Does that mean that we can have all that number of versions for a single class? 这是否意味着我们可以为一个类拥有所有数量的版本? I assume not.
我认为不是。 I'm seeing it to be much shorter primitive.
我看到它的原始性要短得多。
What is a serialVersionUID and why should I use it? 什么是serialVersionUID,为什么要使用它? doesn't state why the guy implemented this mecanism has chosen it to be a long value.
没有说明为什么实施该机制的家伙选择它作为长期价值。
The type of serialVersionUID
should be long
because that is how it was specified . serialVersionUID
的类型应该很long
因为这是它的指定方式 。 See http://docs.oracle.com/javase/8/docs/platform/serialization/spec/class.html (specifically section 4.6) 请参阅http://docs.oracle.com/javase/8/docs/platform/serialization/spec/class.html (特别是第4.6节)
The reason that the UID is 64 bits is that the risk of accidental UID collision would be too high if (say) 32 bit values were used. UID为64位的原因是,如果使用(例如)使用32位值,则意外UID冲突的风险会很高。
The default serial version UID generation scheme creates a hash based on classes methods and fields. 默认的串行版本UID生成方案基于类方法和字段创建哈希。 There is a small, but non-zero, that two different classes will have the same default UID.
有一个很小但非零的值,即两个不同的类将具有相同的默认UID。 If this happens, then the deserializer may not notice that serialized form of the object is incompatible with the slass we are trying to deserialize to.
如果发生这种情况,那么反序列化程序可能不会注意到该对象的序列化形式与我们要反序列化的对象不兼容。 Bad things would then happen.
坏事就会发生。
If 32 bit UIDs were used, the chance that two incompatible classes had the same UID would be one in 2 32 . 如果使用32位UID,则两个不兼容的类具有相同的UID的机会是2 32之一 。 That is about one chance in 4 billion.
那大约是40亿的机会。 That is too large a chance.
机会太大了。 With 64 bit UID values, the change is one in 2 64 .
对于64位UID值,更改为2 64之一 。 That is about one chance in 16 quadrillion.
那大约是16万亿次的机会。 That was deemed (by the designers) to be an acceptably small probability.
(设计者)认为这是一个可接受的小概率。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.