scala2.9中@serializable注释已不鼓励使用

之前允许通过注释的方式表示一个class是可序列化的:

@serializable class X 

现已不鼓励,而用extends Serializable来替代

class X extends Serializable

在邮件列表里有解释为何不鼓励

The reason is that the compiler converts the annotation only during
type-checking, so depending on the order in which things type check,
there might be an error message (“required: Serializable”) or not.

The correct behavior would be to do the transformation earlier, but this is kind of a hack as some of you know (@BeanProperty), and we reallywant to avoid more annotations that influence typing.

完整见这里,以后应该直接用 extends Serializable
另, @SerialVersionUID(42) 这个注释不变。

scala2.9中@serializable注释已不鼓励使用》上有1条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注