• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

serialVersionUID question

 
Abhimanyu Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I came to know that " The identifier that is part of all classes is maintained in a field called serialVersionUID."
But I am not able to access this field directly (say through a print statement, like System.out.println(serialVersionUID); ). So where is this value stored ? Also, i didnt find it in the class file when i opened it with decompiler.

Thanks in advance.

Abhimanyu.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the documentation I found, if you do not define a static final long serialVersionUID in your Serializable class, the ObjectOutputStream will compute one. The purpose being to avoid incompatible versions of a class being created by object serialization.
Bill
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo

I got a similar problem with this (but with an other flavor), the non static inner classes can not be serializated (as long the content class is not serializable). The explication was that a non static inner can not have a static member and if the content class is serializable its serialUID member can be access by the inner class.

I hope I was right ? What you think ?
 
Abhimanyu Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mihai Radulescu:
Hallo
The explication was that a non static inner can not have a static member.


Just one sidenote. Non static inner class can have static final variables (as they are constants). For ex.


-Abhimanyu.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeep It seamns that you have right Abhimanyu, a inner calss can have constants (final static). Good point!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic