Serializable
SerialVersionUID
@SuppressWarnings("serial")
Sample with warning
Person.java
package sample;
import java.io.Serializable;
public class Person implements Serializable {
public String name;
public SerializablePerson(String name) {
this.name = name;
}
}
If you compile with the option (to give all warnings)
javac -Xlint SerializablePerson.java
I get a warning (It may not be displayed on Eclipse depending on the settings (Preferences-> Java-> Compiler-> Error / Warning))
Japanese
Serializable.java:5:warning: [serial]SerialVersionUID is not defined in the serializable class Serializable
English (probably)
The serializable class Mutter does not declare a static final serialVersionUID field of type long
It does not appear when executed with annotations.
Person.java
package sample;
import java.io.Serializable;
@SuppressWarnings("serial")
public class Person implements Serializable {
public String name;
public SerializablePerson(String name) {
this.name = name;
}
}
What I know about the esoteric Serializable specification, or my understanding Add Star The story of responsibility for inheritance was very helpful
Recommended Posts