4

In my Eclipse I was trying example on serialization and I came across following warning

enter image description here

I know what serialVersionUID is and what is it's significance in Serialization. I have following questions about this warning

  1. How does IDE assign default value. Is it hard coded in the IDE?
  2. When it says generate id what parameters are used to generate new id?
  3. Not sure what the 3rd option is. Says something about suppress annotation. Does that mean no id is assigned at all. In that case what is used in serialization?
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • 1
    Read this. http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it – peter.petrov Jan 06 '14 at 18:24
  • Suggestion: Since first two questions are strictly about `Eclipse`, add it as a tag. – PM 77-1 Jan 06 '14 at 18:25
  • It seems to me that options `2` and `3` are *basically* the same as far as `serialVersionUID` itself is concerned: you will not get warnings at compile-time and Java will generate an ID for you at run-time. – PM 77-1 Jan 06 '14 at 19:19
  • Apparently not. Option 2 will generate serialVersionUID which will remain constant and will be used there after. Even if the class is modified later this value being the same will not affect serializarion/deserialization process. Whereas 3rd option will give a value at runtime which will differ in case class is modified later. – Aniket Thakur Jan 06 '14 at 19:32

1 Answers1

3

How does IDE assign default value. Is it hard coded in the IDE?

yes default is hard coded value, which is 1L

When it says generate id what parameters are used to generate new id?

generally method fields and method signatures should used to determine it, since you are asking specifically about eclipse, not sure about it, there is a serialver utillity which simply gives you serialVersionUID for your class

$serialver A
serialver A:    static final long serialVersionUID = -609421954100196333L;

Not sure what the 3rd option is. Says something about suppress annotation. Does that mean no id is assigned at all. In that case what is used in serialization?

it says, instruct java compiler to not complain about this particular warning for this case by adding @SuppressWarning annotation


Also See

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438