0

I want to serialize a Java class because a warning: The serializable class GuiLote does not declare a static final serialVersionUID field of type long. Eclipse recommends this two options: Add default serial version ID and Add generated serial version ID. What the difference between them? Eclipse add this for default serial version ID:

/**
 * 
 */
private static final long serialVersionUID = 1L;

Or add this for generated serial version ID:

/**
 * 
 */
private static final long serialVersionUID = 8534363180966005148L;

This is my code:

public class GuiLote extends JInternalFrame implements ActionListener { ... }

Roby Sottini
  • 2,117
  • 6
  • 48
  • 88
  • possible duplicate of [Why generate long serialVersionUID instead of a simple 1L?](http://stackoverflow.com/questions/888335/why-generate-long-serialversionuid-instead-of-a-simple-1l) – SharpKnight Mar 26 '14 at 18:09

1 Answers1

0

Serial version ID is used to determine if a serialized version of your object (from disk, network etc) can be deserialized into the current application. If the ID-s match, the object is deserialized if not, an exception is thrown. Basically default means that it's set to 1, generated will calculate a unique number taking all the fields in the class into account.

If an older representation of your object is deserialized and there are new fields that were not present in the old version these will come out as null's. Therefore you have a choice, either fail fast and refuse to deserialize if the versions do not match or live with the nulls and maintain backwards compatibility with serialized data.

anttix
  • 7,709
  • 1
  • 24
  • 25