0

I was doing a few experiments with java serialization, and I was curious as to whether every Java class has to have its own serialversionUID or whether it has to be unique. I was thinking about naming the UID as the version number of the class. Is this a good idea?

Sarah Szabo
  • 10,345
  • 9
  • 37
  • 60

2 Answers2

1

It does not need to be unique i.e. it's not necessary every serializable
Java class to have its own different (i.e. unique) serialVersionUID value.

See here:

What is a serialVersionUID and why should I use it?

The accepted answer contains all details which, I guess,
you would need to know (for now) about the serialVersionUID.

Community
  • 1
  • 1
peter.petrov
  • 38,363
  • 16
  • 94
  • 159
-2

No it is not mandatory to define serialVersionUID with Serializable Class because it automatically created and assigned to every class. But if explicitly specify it then it takes that into account or else it is implicitly created. If you assign it by yourself then it needs to be unique.

Indrabhushan
  • 98
  • 10
  • 1
    Doesn't answer the question. He asked whether it needs to be *unique.* You haven't addressed that in any way. – user207421 May 20 '14 at 21:38