This is what I tried:
I built the project with the -Xlint:serial
option, and I got this warning:
MyClass.java:42: warning: [serial] serializable class <anonymous mypackage.MyClass$1> has no definition of serialVersionUID
SerializableClass myObject = new SerializableClass() {
1 warning
Then copied the anonymous class name as parameter for serialver
:
>serialver -classpath dist\Example.jar mypackage.MyClass$1
mypackage.MyClass$1: static final long serialVersionUID = 23L;
I'm not going to serialize it, and I've read that it is not recommended to serialize objects of anonymous classes.
Is it a better practice to leave it as 1L
, or to have no definition of serialVersionUID
at all?