Why serialVersionUID is not enforced by Java -
serialversionuid seems me have loose specification. body developing class serializable interface can burn hands invalidclassexception. also, saw fellow dev using int datatype rather long.
so, question why java designers , developers did not more concrete whenever implement serializable have implement method setting serialversionuid hashcode method.
so, missing ? not seem double edged sword me.
update 1:
my bad gave wrong example comparing class level thing instance level thing.i have seen many production issues across different companies because of this. general idea cant made more strict compiler in way.
so, question why java designers , developers did not more concrete whenever implement serializable have implement method setting serialversionuid hashcode method.
if understand correctly, saying there should method calculate serialversion. can see problems this:
how application program calculate decent serial version? note must calculated type information ... not values of fields.
calculating serial version @ run time (repeatedly) expensive.
if have lazy programmers don't use "serialver" tool calculate proper version number, same lazy programmers implement (hypothetical) method return bogus number ... , started.
there use-cases not changing serial version id intentional.
no. real solution problem of lazy programmers code reviews.
or ... maybe ... tooling either regenerate serialversion constants, or flag them suspicious.
note tools can't pick of cases there going problem. however, neither can code-reviewer. , code-reviewers tired, have paid, etc.
(finally, might idea if ide's didn't offer setting constant -1 quick-fix ...)
but general idea cant made more strict compiler in way.
it not compiler thing. runtime behavior of specific set of library classes. classes use unsafe ... compiler not aware of significance of serialversionid variable.
Comments
Post a Comment