| Author |
private(?) writeObject/readObject
|
Roely de Vries
Greenhorn
Joined: Jan 06, 2007
Posts: 1
|
|
Question about writeObject and readObject, In this code fragment b cannot be serialized,therefore it is marked as transient in A. A is serialized an deserialized by TestSer. Because A has the private methods writeObject and readObject instead of os.defaultWriteObject and ois.defaultWriteObject. The question is, how is this possible? writeObject and readObject are private methods of A, so how can they be invoked by the serialization proces? (edited: added tags) [ January 30, 2007: Message edited by: Barry Gaunt ]
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16680
|
|
The question is, how is this possible? writeObject and readObject are private methods of A, so how can they be invoked by the serialization proces?
Other questions that you may also ask include: - How does the defaultReadObject() method of the stream object access the private instance variables? - How come the readObject() method doesn't call the super.readObject() method? Don't the parent class have special serialization needs too? - How come all readObject() and writeObject() methods are private? Serialization is one area where the "basic rules of Java" does not apply. You need to learn it independently -- without thinking in java. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: private(?) writeObject/readObject
|
|
|