I periodically see Java classes with the following structure:
class MyClass implements Serializable {
private static final long serialVersionUID = 1L;
private void writeObject(final java.io.ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
}
private void readObject(final java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
s.defaultReadObject();
}
}
As I understand it, for serialization by default you need to declare an interface implementation serializableand define serialVersionUID. Is there any reason for declaring write / read methods using only the standard implementation? I'm tired of analyzer warnings about code duplication.
You do not see a really clear guide for this topic. Everything is either somewhat outdated or rather subjective.
source
share