Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

serialization  RSS feed

 
shabnam aazmi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is method serialized during the process of serialization
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Conceptually, a method is part of the class itself, not part of an instance of the class. Serialisation writes out the instance data.
 
gaurav abbi
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Peter,
serialization also applies to static variables, the only thing is we need to seperately serialize and desrialize them.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by gaurav abbi:
hi Peter,
serialization also applies to static variables, the only thing is we need to seperately serialize and desrialize them.


No, this is at best confusing and at worst wrong.

You can give a static object reference to writeObject(), but you are then serialising the instance pointed to by that static object reference.

You could write custom serialisation code to write static fields, as you can write custom serialisation code to write anything you like. However, getting static data serialised with every instance would almost certainly be wasteful and would likely cause problems on reading.

By the way, Java doesn't really have "static variables" - not in the sense that C has, say. In Java, the only things usually called "variables" are the local variables inside methods. Static fields and instance fields are called "fields".
[ March 13, 2007: Message edited by: Peter Chase ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!