serialVersionUID naming convention
Asked Answered
D

1

8

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.

Derogative answered 12/1, 2012 at 14:6 Comment(1)
That's the way the serialization API is written ;)Hopefully
S
6

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.

Showalter answered 12/1, 2012 at 14:9 Comment(2)
Don't think so, serialVersionUID was introduced in Java 1.5Derogative
@WojtekOwczarczyk. It was introduced along with Serialization in Java 1.1.Gilmagilman

© 2022 - 2024 — McMap. All rights reserved.