Yeah, what confused me about Hashtable's serialized form was the fact that
it gives a readObject() / writeObject() specification but then goes on to
list two fields (loadFactor and threshold) *which aren't mentioned at all*
in the aforementioned specification. Are those fields unimportant, then?
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?
-jaz
> -----Original Message-----
> From: Scott Miller [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 16, 1998 9:21 AM
> To: Jon Zeppieri
> Cc: Classpath List
> Subject: Re: Dictionary / Hashtable implementation
>
>
> > I just subscribed to this list, so, for all I know, this may
> already have
> > been taken care of, but....
> >
> > I just finished a java.util.Hashtable (JDK1.2 compliant)
> implementation, and
> > am offering it up, if it is wanted. Where should I send it?
> Great! One less thing in the Util package to deal with.
>
> > Oh -- I don't quite understand the "Serialized Form" for
> Hashtable, so it
> > isn't yet binary compatible with the JDK. It's also at present wholly
> > undocumented. I'm perfectly willing to complete both tasks,
> but someone is
> > going to have to explain the finer points of the former to me.
> I think I can help you out here. The Serialized Form gives you a
> description of what fields get serialized when the Object is serialized.
> There can be no additional fields in the Object than those listed in
> Serialized Form to be binary compatible (Unless the field is transient).
>
> In Hashtable's case, the Serialized Form asks that you implement a
> readObject and writeObject method. Essentially, you have to serialize the
> Hashtable yourself. You'll want to use the methods of the
> ObjectOutputStream to components of the Hashtable over the stream. It
> asks that you send the capacity (as an int), then the size (also an int I
> believe), then use ObjectOutputStreams writeObject for each key-value
> pair. So roughly:
>
> s.writeInt(capacity);
> s.writeInt(size);
> for (int i=0; i<size; i++) {
> s.writeObject(keyAt(i));
> s.writeObject(valueAt(i));
> }
>
> For the readObject, reverse the process.
>
> Somebody smack me if I'm wrong.
>
> Scott
>
> --------------------------------------------------------------------------
> Java Programmer Scott Gregory Miller Linux afficionado
> Graphics Designer [EMAIL PROTECTED] General Loony
> --------------------------------------------------------------------------
>
>