Automatically generate serial version UID in Eclipse

This is perhaps not the answer you're looking for. Presumably, you use Eclipse to generate the same special value that Java would automatically calculate for your class if you didn't explicitly specify it, something like:

    private static final long serialVersionUID = 4125965356358329466L;

But there's no good reason to rely on this same algorithm for newly authored classes. What matters is you specify a value, any value. So why not simply do the following?

    private static final long serialVersionUID = 1L;

You could then put this code in Eclipse's new class template.


Not sure if you have got answer to this. But Eclipse does allow to create serialVersionUID in one go for all classes implementing Serializable. Although, it is not exactly same what you want. However, it will serve the purpose with fewer clicks.

Right-click Project -> Source -> Clean Up...

  • Select Use custom profile. then click Configure

clean-up-screen-1

  • Click Missing Code tab. Under Potential programming problems select Add serial cersion ID. Click OK

clean-up-screen-2

  • Now you will see one step being added as highlighted

clean-up-screen-3

After clicking Finish, Eclipse will generate serialVersionUID.

Tags:

Java

Eclipse