Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 535
Aleksandr Dubinsky Avatar asked Nov 25 '17 04:11

Aleksandr Dubinsky


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.

like image 84
user207421 Avatar answered Sep 21 '22 03:09

user207421