I would like to remove some warnings for some classes by generating an automatic serial version ID. In Eclipse, this is trivial to do - the IDE can generate one automatically and add it to the class. However, I don't see this functionality in NetBeans. Is it available? If so, where is it? If not, is there a plugin that can enable it?
This is trivial to do manually as well, unless you need to stay compatible with existing serialized instances. Just copy this line into the class:
private static final long serialVersionUID = 1L;
Note that there is absolutely no requirement for the serialVersionUID
to be unique across classes.
Actually my solution to that "problem" was to deactivate that warning in my project configuration (I use Eclipse but I guess for NetBeans is the same) as IMHO it's a wrong warning: not having a serialVersion is the safest choice because the JVM calculates one that is unique on launch (something like the hash of the class) while adding it explicitly then burdens you to take care to update it if and only if you made incompatible changes to your code.
So, if you do not care about that, it's better to avoid that value (this way it's only compatible with version that are compatible for sure, but with some false-positives: it thinks that's not compatible, but in fact it would) instead of putting there a fixed value that you would (probably, in my case) forget to update when needed, leading to actual validity errors (false-negatives: it thinks that it is compatible but it is not).
To disable these warnings in Netbeans :
- Open: Tools -> Options
- Open: Editor -> Hints tab
- Select Language: Java
- Uncheck Standard Javac warnings -> Serialization
- OK
I also had to clear ~/.netbeans/6.8/var/cache and restart Netbeans to clear the warnings from the Tasks list.