0

One more silly question. But wanted to ask because its spinning my head from last 1 hour.

We all know serialVersionUID is unique. What is the level of uniqueness? Should it be unique in the project or workspace or server?

Will it cause IllegalClassCasteException or any other exception if two classes in the same workspace have same serialVersionUID(copy pasted)?

If its unique per project/workspace then why Eclipse provide default serialVersionUID (1L)?

Mithun Khatri
  • 636
  • 3
  • 9
  • 22

2 Answers2

2

We all know serialVersionUID is unique

No. It doesn't have to be unique at all. All your classes can have the same serialVersionUid if you want.

Two versions of a given class, if they are compatible regarding serialization, should have the same serialVersionUid. Java will consider them incompatible if they don't have the same serialVersionUid, even if the changes between the two versions of the class doesn't actually break their compatibility.

And if two versions of a class are incompatible regarding serialization, then it's a good idea to make that obvious by changing the serialVersionUid.

It seems you don't even know what serialVersionUid is all about. If that's the case, then I would advise to not add any serialVersionUid to any of your classes, and to let the JVM figure it out by itself.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
2

serialVersionId will help when object serialize and transport and run in some other enviornment mainly other jvm then serialVersionId will deseralize and check it competes the enviornment. so as long as you have same jvm you need not to worry. thats why eclipse provide 1L

Sanjay Rabari
  • 2,091
  • 1
  • 17
  • 32