wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serialization" Watch "Serialization" New topic
Author

Serialization

Neelesh Bodas
Ranch Hand

Joined: Jul 20, 2006
Posts: 107
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

Joined: Sep 28, 2004
Posts: 18545
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Serialization
 
Similar Threads
Island of Isolation
Private Variable access
a switch problem
Overloading Ambiguously