I have a discussion with a colleague about the serialVersionUID of serializable classes: He always start with a serialVersionUID = 1L
and then increments it by one when there are some significant changes to the class.
The JDK classes always seem to use more complex, generated
serialVersionUIDs like in the java.lang.String
class:
private static final long serialVersionUID = -6849794470754667710L;
Now my colleague asks about the advantage of this kind of serialVersionUID versus much simpler serialVersionUID like 1L, 2L, 3L... ?
We also searched on SOF, but are not very satisfied with the answers given, for example in Why generate long serialVersionUID instead of a simple 1L?.
In my opinion the advantage of using generated IDs is that it does not need any information about the 'older' class versions. But when incrementing the IDs manually, you have to know the highest value so far. This might sound trivial (by just looking at the current serialVersionUID and increase it by 1) but could be more complex in bigger software projects, bigger development teams or in distributed environments.