CONTENTS | PREV | NEXT | Java Object Serialization Specification |
AnObjectStreamField
represents 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 ofObjectStreamField
components 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(); }ObjectStreamField
objects 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, aClass
object specifying the type of the field, and aboolean
flag (implicitlyfalse
for 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.readUnshared
andObjectOutputStream.writeUnshared
methods in sections 3.1 and 2.1, respectively).The
getName
method returns the name of the serializable field.The
getType
method returns the type of the field.The
getTypeString
method returns the type signature of the field.The
getTypeCode
method 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
isPrimitive
method returnstrue
if the field is of primitive type, orfalse
otherwise.The
isUnshared
method returnstrue
if values of the field should be written as "unshared" objects, orfalse
otherwise.The
getOffset
method returns the offset of the field's value within instance data of the class defining the field.The
setOffset
method allowsObjectStreamField
subclasses to modify the offset value returned by thegetOffset
method.The
compareTo
method comparesObjectStreamFields
for use in sorting. Primitive fields are ranked as "smaller" than non-primitive fields; fields otherwise equal are ranked alphabetically.The
toString
method returns a printable representation with name and type.