Tuesday, January 8, 2019

Is serialVersionUID inherited by subclasses, if I have default serialVersionUID in superclass? Similar to when the superclass is serializable then subclasses are also serializable.

Answer :
Is serialVersionUID inherited by subclasses, if I have default serialVersionUID in superclass?
Yes it is inherited, but no, Serialization won't consider it as belonging to the subclass and not use it.
Similar to when the superclass is serializable then subclasses are also serializable.
It isn't similar. Serializable is an interface and it is subject only to the rules of the language. serialVersionUID is a special field with its own rules enforced by ObjectInputStream.

No comments:

Post a Comment