3

I am using the serialized classes in java and in those classes I need to specify the serialVersionUID with some long number to be initialized. As a default it takes as

    private static final long serialVersionUID = 1L;

Or else I can initialize the same with some other long number too, like as bellow:

    private static final long serialVersionUID = 5561040348988016571L;

some very big number.

My question is: Does it really matter which value we initialize to serialVersionUID or not?

2
  • My question was not basically why we need serialVersionUID but instead, does it matter if we initialize it with 1L and 5561040348988016571L which is preferred one? Commented Feb 13, 2014 at 7:30
  • Read the link I gave you, and you'll understand. I'm surprised you care about the value it should have but don't care if a serialVersionUID should exist at all. Commented Feb 13, 2014 at 7:32

2 Answers 2

1

My question is does this really matters which value we initialize to serialVersionUID or it doesn't matter.

No, it doesn't matter, unless you already have existing serializations (e.g. files) that were made before you added this member. In that case you must use the value output by the serialver utility when run on the .class file as it was when those serializations were made.

Sign up to request clarification or add additional context in comments.

Comments

0

If your object state is not going to serialized, then it doesn't matter else you will have to generate serialVersionUID everytime class structure changes (u can use eclipse default UID generation policy).

2 Comments

No you won't. You should never change a serialVersionUID.
EJP. Do you mean to say even though my class structure changes i should continue with same serializeversionuid?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.