Hi,
The serialVersionUID is recommended to be declared as "private" and
warrant a warning.
There's no value to it being public or protected and it is just noise in
the javadoc of the class.
The Serialized Form of each class documents the value of the
serialVersionUID regardless of the
access modifier.
Similarly, the writeReplace and readResolve methods that are specified to
allow ANY-ACCESS-MODIFIER are recommended to be private also, for the
same reasons.
Regards, Roger
On 3/13/21 4:07 AM, Zheka Kozlov wrote:
Hi!
The javadoc of java.io.Serial [1] says that serialVersionUID is private.
But the javadoc of Serializable [2] says it can have any access modifier.
Who is right here? When I write the following code, should there be a
warning or not?
import java.io.Serial;import java.io.Serializable;
public class SerExample implements Serializable {
@Serial // warning or not?
public static final long serialVersionUID = 2L;}
This question originated in this [3] discussion in the IDEA bugtracker.
With best regards, Zheka.
[1]
https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/io/Serial.html
[2]
https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/io/Serializable.html
[3] https://youtrack.jetbrains.com/issue/IDEA-230392