views:

1237

answers:

4

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?

+2  A: 

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.

Michael Borgwardt
Although this is a good suggestion, I decided to ignore the warning as it's not THAT important to have on this particular project. I just didn't like the warning showing up.
Thomas Owens
+2  A: 

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).

lapo
That depends on how you use serialization. If you will be serializing classes across different JVM's, that is from one JVM to another, that may cause incompatabilities.
Yishai
It seems like this approach will work best on my current project, but I didn't see a place to turn this warning off everywhere (and having a lot of suppress warning annotations seems bad) in NetBeans.
Thomas Owens
And I was able to find it...
Thomas Owens
+1  A: 

Hi,

It seems like out of the box NetBeans doesn't support the feature, but plug-ins do.

Please have a look at

link 1, link 2 and link 3

Koekiebox
A: 

To disable these warnings in Netbeans :

  1. Open: Tools -> Options
  2. Open: Editor -> Hints tab
  3. Select Language: Java
  4. Uncheck Standard Javac warnings -> Serialization
  5. OK

I also had to clear ~/.netbeans/6.8/var/cache and restart Netbeans to clear the warnings from the Tasks list.

flygandehund