| CONTENTS | PREV | NEXT | Java Object Serialization Specification |
AnObjectStreamFieldrepresents a serializable field of a serializable class. The serializable fields of a class can be retrieved from theObjectStreamClass.The special static serializable field,
serialPersistentFields, is an array ofObjectStreamFieldcomponents that is used to override the default serializable fields.package java.io; public class ObjectStreamField implements Comparable { public ObjectStreamField(String fieldName, Class fieldType); public ObjectStreamField(String fieldName, Class fieldType, boolean unshared); public String getName(); public Class getType(); public String getTypeString(); public char getTypeCode(); public boolean isPrimitive(); public boolean isUnshared(); public int getOffset(); protected void setOffset(int offset); public int compareTo(Object obj); public String toString(); }ObjectStreamFieldobjects are used to specify the serializable fields of a class or to describe the fields present in a stream. Its constructors accept arguments describing the field to represent: a string specifying the name of the field, aClassobject specifying the type of the field, and abooleanflag (implicitlyfalsefor the two-argument constructor) indicating whether or not values of the represented field should be read and written as "unshared" objects if default serialization/deserialization is in use (see the descriptions of theObjectInputStream.readUnsharedandObjectOutputStream.writeUnsharedmethods in sections 3.1 and 2.1, respectively).The
getNamemethod returns the name of the serializable field.The
getTypemethod returns the type of the field.The
getTypeStringmethod returns the type signature of the field.The
getTypeCodemethod returns a character encoding of the field type (`B'forbyte,`C'forchar,`D'fordouble,`F'forfloat,`I'forint,`J'forlong,`L'for non-array object types,`S'forshort,`Z'forboolean, and`[`for arrays).The
isPrimitivemethod returnstrueif the field is of primitive type, orfalseotherwise.The
isUnsharedmethod returnstrueif values of the field should be written as "unshared" objects, orfalseotherwise.The
getOffsetmethod returns the offset of the field's value within instance data of the class defining the field.The
setOffsetmethod allowsObjectStreamFieldsubclasses to modify the offset value returned by thegetOffsetmethod.The
compareTomethod comparesObjectStreamFieldsfor use in sorting. Primitive fields are ranked as "smaller" than non-primitive fields; fields otherwise equal are ranked alphabetically.The
toStringmethod returns a printable representation with name and type.