> From: Scott Miller [mailto:[EMAIL PROTECTED]]
> 
> 
> > Hmm..to clarify:  the serialized form documentation mentions two 
fields
> > which it then omits from its writeObject() / readObject() 
> specification.  If
> > those fields aren't written out to the object stream, then are they
> > unimportant?  And if so, why does the documentation mention them?
> 
> Okay, I didn't see those two fields when I was looking the first time. 
> I'm not exactly sure what loadFactor is, but threshold is described..
> These ARE important to serialize.  And in fact, your implementation 
should
> try to use them.
> 
> As for serializing them.  Hmmm.. What I would suggest doing is setting 
up
> a Sun Hashtable and then a Test class of your own.  Have the Sun app
> serialize its Hashtable, and your test Class read from that stream.   
You
> can manipulate the contents of the Hashtable (Having no values for
> example, and set the capacity to something recognizable), and see if 
you
> cant reverse engineer where the loadFactor and threshold are coming 
down
> the stream.  
> 

Threshold is a calculated value, capacity * loadFactor.  I'm sure you 
already have loadFactor in your class.  It is important to serialize 
because it is a user-specified parameter (see the second form of 
constructor).

Why they would bother serializing threshold is beyond me, since it is a 
calculated value.  This looks like a spec bug.  Submit to the Bug Parade 
at the Java Developer Connection (http://java.sun.com/jdc).

> To be honest, I don't think you even need to do this.  I don't have a
> crystal clear idea on how serialization works.  Somebody help me out 
here,
> but I think Java will serialize the fields listed in the Serialized 
Form
> automatically, then call the Hashtable's read/writeObject methods to
> handle the rest.
> 

This will definitely not happen.  It will either: (a) serialize whatever 
non-transient fields you have, or (b) call read/writeObject to do *all* 
the serialization.  I'm not sure how it affects super/subclasses, but in 
this case the behavior is clear.  If you do read/writeObject, nothing 
will be serialized except the stuff you want serialized.

--John Keiser


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Reply via email to