This has become a pet peeve of mine. I write a class, and implement Serializible
. Then eclipse warns me that I don't have a serialVersionUID
, so I select "Add generated serialVersionUID" or "Add default serialVersionUID" and I end up with something like this:
/** * */ private static final long serialVersionUID = 4049849541314027178L;
Most of the time I don't want to add a comment, so I have to go and delete the comment. I would rather the default be no comment, but I've looked through the code templates in preferences and haven't figured out how to change this. I simply want it to look like this:
private static final long serialVersionUID = 4049849541314027178L;
The serialVersionUID attribute is an identifier that is used to serialize/deserialize an object of a Serializable class.
File -> Settings -> Editor -> Inspections -> Java -> Serialization issues : Find serialization class without serialVersionUID and check it. Back to the editor, clicks on the class name, ALT + ENTER (Windows), it will prompts the Add serialVersionUID field option. A new serialVersionUID is auto-generated.
SerialVersionUID is a unique identifier for each class, JVM uses it to compare the versions of the class ensuring that the same class was used during Serialization is loaded during Deserialization. Specifying one gives more control, though JVM does generate one if you don't specify.
It's using the template for any eclipse-generated field.
You can change it in
Preferences -> Java -> Code Style -> Code Templates -> Comments -> Fields
... either globally or per-project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With