问题描述
有什么可行的理由为什么serialVersionUID字段未命名为SERIAL_VERSION_UID?
Is there any viable reason why serialVersionUID field is not named SERIAL_VERSION_UID?
根据 java.io的文档可序列化:
ANY-ACCESS-MODIFIER静态最终长serialVersionUID = 42L;
ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
在引用 Java命名约定均为
我找到了Sun在1997年发布的名为 Java代码约定的文档,在第16页的第9节中说:声明了类常量和ANSI的变量的名称 常量应该全部大写,并用下划线("")分隔单词."_
I found a document published by Sun in 1997 called Java Code Conventions that says in Section 9 on page 16 "The names of variables declared class constants and of ANSI constants should be alluppercase with words separated by underscores ("")."_
所以我的猜测是Sun并没有在自己的代码上强制执行自己的标准.
So my guess is that Sun just didn't enforce their own standards on their own code.
这篇关于serialVersionUID命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!