SerialVersionUID JavaDoc?
SerialVersionUID JavaDoc?
在向我的 Java 程序添加文档时,我意识到大多数 类 需要声明一个 serialVersionUID
常量 属性。我应该如何记录这个 属性?如果我使用默认的与生成的串行版本 UID,我的记录是否不同?
/**
* What goes here? "A unique serial version identifier"
*/
private static final long serialVersionUID = -8922096951749901688L;
首先,您提供的 serialVersionUID
评论似乎是正确的 但没有必要。
serialVersionUID
需要作为 Serializable
对象的一部分( 并非全部 java 类)并被使用在此对象的序列化/反序列化期间。
作为一般规则。 始终检查 API
在这种情况下,Serializable
API,在底部!!
The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long:
ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
So you're saying that it should actually not be documented whatsoever because there is javadoc for it already? When I omit the javadoc and mouseover it, it does not show anything :/
它是 Serializable
界面的一部分,所以恕我直言,没有必要...无论如何,您可以使用自己的评论 + @see
注释。类似这样的东西(不确定是否可行,现在无法创建 javadoc...)
/**
* A unique serial version identifier
* @see Serializable#serialVersionUID
*/
在向我的 Java 程序添加文档时,我意识到大多数 类 需要声明一个 serialVersionUID
常量 属性。我应该如何记录这个 属性?如果我使用默认的与生成的串行版本 UID,我的记录是否不同?
/**
* What goes here? "A unique serial version identifier"
*/
private static final long serialVersionUID = -8922096951749901688L;
首先,您提供的 serialVersionUID
评论似乎是正确的 但没有必要。
serialVersionUID
需要作为 Serializable
对象的一部分( 并非全部 java 类)并被使用在此对象的序列化/反序列化期间。
作为一般规则。 始终检查 API
在这种情况下,Serializable
API,在底部!!
The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long:
ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
So you're saying that it should actually not be documented whatsoever because there is javadoc for it already? When I omit the javadoc and mouseover it, it does not show anything
:/
它是 Serializable
界面的一部分,所以恕我直言,没有必要...无论如何,您可以使用自己的评论 + @see
注释。类似这样的东西(不确定是否可行,现在无法创建 javadoc...)
/**
* A unique serial version identifier
* @see Serializable#serialVersionUID
*/