Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The serializable class does not declare a static final serialVersionUID field

 
Siegfried Heintze
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What the heck is eclipse 3.2 talking about when it gives me the following warning:

"The serializable class XYZ does not declare a static final serialVersionUID field of type long"

Eclipse will generate such a field for me. I'm just creating a descendant of class Applet.

thanks,
siegfried
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you explicitly put such a field into a serializable class, then you can use it to provide versioning for serialized data files containing this class. Class versions with the same SerialVersionUID have compatible serialized data, by definition, even if the class changes.

But if this doesn't matter to you, then just ignore the warning.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For your information: in Eclipse you can change the importance of compile errors/warnings to your taste by Window - Preferences - Java - Compiler - Errors/Warnings. Specific this one can be found in the group called "Potential programming problems".
 
Robert Hill
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Disabling it might cause trouble down the road. If you mean to serialize an object the warnings will help you remember.

You can keep the warning turned on and either ignore it or get it out of sight by placing this line above public class ... : @SuppressWarnings("serial")
 
Siegfried Heintze
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does someone have a favorite URL/tutorial that describes how one uses this unique value for versioning with serialization?

Thanks,
Siegfried
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic