How to generate serial version UID in Intellij

catch23 picture catch23 · Jul 4, 2014 · Viewed 123.6k times · Source

When I used Eclipse it had a nice feature to generate serial version UID.

But what to do in IntelliJ?

How to choose or generate identical serial version UID in IntelliJ?

And what to do when you modify old class?

If you haven't specify the id, it is generated at runtime...

Answer

Serhii Maksymchuk picture Serhii Maksymchuk · Mar 15, 2016

Without any plugins:

You just need to enable highlight: (Idea v.2016, 2017 and 2018, previous versions may have same or similar settings)

File -> Settings -> Editor -> Inspections -> Java -> Serialization issues -> Serializable class without 'serialVersionUID' - set flag and click 'OK'. (For Macs, Settings is under IntelliJ IDEA -> Preferences...)

Now, if your class implements Serializable, you will see highlight and alt+Enter on class name will propose to generate private static final long serialVersionUID.

UPD: a faster way to find this setting - you might use hotkey Ctrl+Shift+A (find action), type Serializable class without 'serialVersionUID' - the first is the one.