• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialization

 
Neelesh Bodas
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is about the methods defaultWriteObject() and defaultReadObject().
Java allows me to define my own version of writeObject() in the class which implements Runnable :


My question is : how does defaultWriteObject get to know about the "this" reference while getting executed? (It must be knowing about it since it does the necessary serialization). We never pass "this" reference to it!!

[ July 20, 2006: Message edited by: Neelesh Bodas ]
[ July 20, 2006: Message edited by: Neelesh Bodas ]
 
Henry Wong
author
Marshal
Pie
Posts: 21496
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is : how does defaultWriteObject get to know about the "this" reference while getting executed? (It must be knowing about it since it does the necessary serialization). We never pass "this" reference to it!!


The ObjectOutputStream already knows which object (and part of) is in progress. It is the ObjectOutputStream that called your WriteObject() method, passing a reference to itself. So, basically, calling defaultWriteObject() just means to write the current piece in progress to the stream.

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic