When the class implements Serializable I want the serialVersionUID field to be auto-created by IntelliJ IDE. This feature comes in automatically in Eclipse. But the former does not.
How do I make IntelliJ create the field or warn me that it is not defined in the class yet?
It is not turned on by default in IntelliJ. Can be easily done by going to the following:
File > Settings > Editor > Inspections > Java > Serialization Issues
Then find and select – Serializable class without ‘serialVersionUID’ – by checking on the box to the right of it.
Similarly, you can search for it once in File > Settings. Keyword for search can be – ‘serialVersionUID’ – without the quotes.
The path or location of this feature on IntelliJ may vary. It should be the same on Linux and Windows for versions 2019 and 2020.
This will only throw a warning. It does not magically create the field in all those classes that implements Serializable straight away. But then IntelliJ will help you create it, like any other decent IDE out there. Go to the class name declaration, you may find that it is subtly highlighted in yellow to hint that there is a user action that can be done. Hover then click on the option – Add ‘serialVersionUID’ field – and you will get the desired result like this one:
private static final long serialVersionUID = 6265605531073886420L;