Aleksandr Dubinsky
Aleksandr Dubinsky

Reputation: 23505

Should I implement `serialVersionUID` on interfaces?

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.

Upvotes: 7

Views: 1717

Answers (1)

user207421
user207421

Reputation: 310957

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.

Upvotes: 6

Related Questions