Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting rid of the comment above Eclipse-generated serialVersionUID

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; 
like image 546
mrip Avatar asked Feb 07 '14 15:02

mrip


People also ask

What is the serialVersionUID in Java?

The serialVersionUID attribute is an identifier that is used to serialize/deserialize an object of a Serializable class.

How do you generate unique serialVersionUID?

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.

Why is serialVersionUID used in Java?

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.


1 Answers

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.

like image 111
slim Avatar answered Oct 05 '22 18:10

slim