Eclipse自动生成serialVersionUID,每次更改 [英] Eclipse auto-generation of serialVersionUID with each change
问题描述
每次更改内容时,是否有一些方法可以生成serialVersionUID? 保存动作似乎没有包含这样的选择 - 有人找到了一些方法吗?
它可以和IDE保存动作或类似的操作,以便我可以恢复更改,如果我这样做不会影响序列化。
祝福,
Touko
编辑:@gustafc:这里有两个要点:
- 如果我已经正确理解,不同的编译器最终可能会使用serialVersionUID的不同值
- 从可序列化API :但是,强烈建议所有可序列化类显式声明serialVersionUID值,因为serialVersionUID的默认计算对类详细信息非常敏感,这些详细信息可能会因编译器实现而异,因此可能会导致意外的InvalidClassE反序列化期间的异常
- 我正在使用类似于在服务器上执行事情的对象的命令模式。所以,尽管对象内容没有改变,但当客户端和服务器上的类内容不同时,可以很容易地了解这些情况。
- 但是再想一想,这不可能适用于自动生成的价值,因为只有内容的变化会改变?所以,其实我想有一个自动递增的serialVersionUID
这个听起来很合理?
总结来说,经过更多的思考,每次更改时增加的自动递增的serialVersionUID将会更好...
Eclipse中没有标准功能来执行此操作。
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 the generation again.
Is there some way to have the serialVersionUID being generated every time I change the contents? The "Save Actions" don't seem to include such an option - has somebody found some way to do this?
It would be nice that it could be combined with the IDE save actions or something similar so that I could revert the change if I were doing that doesn't affect the serialization.
Best regards, Touko
EDIT: @gustafc: There are two main points for this:
- If I have understood correctly, different compilers may end up with different values for serialVersionUID
- From Serializable API :However, it is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassExceptions during deserialization
- I'm using kind of command-pattern like objects doing things at server. So, even though the object content isn't changed, it would be nice to catch the cases when the class content is different at client and server.
- But on thinking another time, this wuoldn't probably work with auto-generated value since only the content changes would change that? So, actually I'd like to have an auto-incremented serialVersionUID
Does this sound sensible?
Summa summarum, after more thinking, an auto-incremented serialVersionUID incremented at each change would be even better...
There is no standard functionality in Eclipse to do this.
这篇关于Eclipse自动生成serialVersionUID,每次更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!