SerialVersionUID naming convention

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

According to docs for java.io.Serializable :

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

ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;

When accessing the Java Naming Convention, all static final (constant) fields must be capitilized with its fragments separated by underscores.

+6
source share
1 answer

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

I found a document published by Sun in 1997 under the name Java Code Conventions, which reads in section 9 on page 16, "Variable class names declared by the constant class and ANSI constants must be completely filled with words separated by underscores (" ")." _

So, I assume that Sun simply did not apply its own standards in its own code.

+4
source

Source: https://habr.com/ru/post/905827/


All Articles