What happened to the generate serialVersionUID feature?

Hi,

It used to be possible to get Intellij to generate the serialVersionUID for serializable objects?

I can not find it in idea 9. Is this a bug or a feature or am I just blind?

--Florian

5 comments
Comment actions Permalink

you need to enable inspection: once done, you'll be notified your class doesn't have serial

(after that use usual mumbo-jumbo:  alt+enter and serial will be created by intellij)

cheers

0
Comment actions Permalink

Actually, you should not be "generating" serial version UIDs. It is a dumb "feature" that stems from the general misunderstanding of how that ID is used by Java. You should be giving these IDs meaningful, readable values, e.g. starting with 1L, and incrementing them each time you think the new version of the class should render all previous versions (that might be previously serialized) obsolete.  All utilities that generate such IDs basically do what the JVM does when the ID is not defined: they generate the value based on the content of the class file, hence coming up with unreadable meaningless long integers. If you want each and every version of your class to be distinct (in the eyes of the JVM) then you should not even specify the serialVersionUID value isnce the JVM will produce one on the fly, and the value of each version of your class will be unique. The purpose of defining that value explicitly is to tell the serialization mechanism to treat different versions of the class that have the same SVUID as if they are the same, e.g. not to reject the older serialized versions. So, if you define the ID and never change it (and I assume that's what you do since you rely on the auto-generation, and you probably never re-generate your IDs) you are ensuring that all - even absolutely different - versions of your class will be considered the same by the serialization mechanism. Is that what you want? If not, and if you indeed want to have control over how your objects are recognized, you should be using simple values that you yourself can understand and easily update when you decide that the class has changed significantly. Having a 23-digit value does not help at all.

Hope this helps. Good luck.
C

4
Comment actions Permalink

I am not sure he asked for java lessons ;-)

0
Comment actions Permalink

Just trying to help, that's all... Anyone can use a tip. Isn't that what forums are for?

0
Comment actions Permalink

no worries here.

Your comment was a good refresher. I was actually looking this up for a colleague of mine. i am sort-of the goto-person for IntelliJ IDEA questions.

cheers,
Florian

0

Please sign in to leave a comment.