java - Do I need to put a serialVersionUID on ancestors of a Serializable class? -
do need put serialversionuid
on ancestors of serializable
class? or on serializable
class itself?
you not need put serialversionuid @ all.
java automatically determine appropriate serial id classes based on fields, methods, etc.
the appropriate time have serialversionuids when storing objects file , need load them later, after have changed code.
or, if transferring data across wire between components using different versions of library.
90% of time people need serialization, real-time, , library version matching on both sides guaranteed. in these cases, not need set serialversionuid, , can cause problems, if have 2 library versions incompatible have not changed sid. start getting weird errors since java thinks they're serially compatible, when actually, they're not.
look @ these questions well:
is there reason use real serialversionuid?
why generate long serialversionuid instead of simple 1l?
what serialversionuid , why should use it?
edit add:
as original question, no don't need worry ancestors. serialversionuid tell java if compatible.
however, if ancestor changed, , serialversionuid did not change, may not compatible though saying is. reason why shouldn't setting @ all.
Comments
Post a Comment