• 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
Sheriff
Posts: 22616
111
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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!