Does the Java serialVersionUID must be static? Can it be an instance variable set by a sub class through constructor?

huangapple go评论77阅读模式
英文:

Does the Java serialVersionUID must be static? Can it be an instance variable set by a sub class through constructor?

问题

Java 的 serialVersionUID 必须是静态的吗?它可以是由子类通过构造函数设置的实例变量吗?

英文:

Java serialVersionUID must be static? Can it be an instance variable set by a sub class through constructor?

答案1

得分: 1

Serializable文档

> 一个可序列化的类可以通过声明一个名为"serialVersionUID"的字段(该字段必须是静态的、final的和long类型的)来显式地声明自己的serialVersionUID

所以它必须是静态的。

英文:

From the Serializable docs.

> A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long.

So it must be static.

huangapple
  • 本文由 发表于 2020年8月28日 18:33:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63632093.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定