• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

serialVersionUID question

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeep It seamns that you have right Abhimanyu, a inner calss can have constants (final static). Good point!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic