Eclipse auto-generation of serialVersionUID with each change

前端 未结 3 1439
[愿得一人]
[愿得一人] 2021-01-04 04:52

Eclipse nicely generates the serialVersionUID for me. But this seems to be passive code generation as the id won\'t be automatically updated as I change the file unless I do

相关标签:
3条回答
  • 2021-01-04 05:33

    There is no standard functionality in Eclipse to do this.

    0 讨论(0)
  • 2021-01-04 05:36

    You could update the serial version at build time with the Ant SerialVer task.

    0 讨论(0)
  • 2021-01-04 05:37

    the id won't be automatically updated as I change the file unless I do the generation again.

    AFAIK default serialVersionUID is just this -- an id generated based on current "shape" of a class. So if you want your id generated when you change anything -- just leave it out.

    However, if you want to change serialVersionUID only sometimes -- just change it. Random modification to the id will do.

    Random number is only little better than consecutive numbers (if you can assume no one else makes up a class with the same qualified name in your environment), so you may even start from serialVersionUID = 1 and increment this number at will.

    0 讨论(0)
提交回复
热议问题