Should I implement `serialVersionUID` on interfaces?

Viewed 1304

Should I add the serialVersionUID field when creating an interface that extends Serializable?

My IDE (Netbeans 8.2) complains that the field is missing. However, to my understanding, serialVersionUID is only applicable to non-abstract classes (the specific classes that will be instantiated during deserialization).

If serialVersionUID is necessary, what should I do about interfaces that extend interfaces? Normally, this field is declared in every class down the class heirarchy. While this is also possible for interfaces, it leads to a different IDE warning that fields hide fields.

1 Answers

No you should not. The serialVersionUID of an interface is nowhere taken into account during the serialization or deserialization process. It is pointless. serialVersionUID is for Serializable classes.

Related