serialVersionUID naming convention

坚强是说给别人听的谎言 提交于 2020-01-14 09:15:47

问题


Is there any viable reason why serialVersionUID field is not named SERIAL_VERSION_UID?

According to the docs for java.io.Serializable:

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;

While referring Java Naming Conventions all static final (constants) fields should be capitilized having its fragments separated with an underscore.


回答1:


Probably because serialVersionUID was defined in the Java serialization API before such conventions existed.

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 (“”)."_

So my guess is that Sun just didn't enforce their own standards on their own code.



来源:https://stackoverflow.com/questions/8836369/serialversionuid-naming-convention

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!