CONTENTS | PREV | NEXT
4.4 The ObjectStreamField Class
An ObjectStreamField represents a serializable field of a serializable class. The serializable fields of a class can be retrieved from the ObjectStreamClass.The special static serializable field, serialPersistentFields, is an array of ObjectStreamField 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, a Class object specifying the type of the field, and a boolean flag (implicitly false 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 the ObjectInputStream.readUnshared and ObjectOutputStream.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' for byte, `C' for char, `D' for double, `F' for float, `I' for int, `J' for long, `L' for non-array object types, `S' for short, `Z' for boolean, and `[` for arrays).
The isPrimitive method returns true if the field is of primitive type, or false otherwise.
The isUnshared method returns true if values of the field should be written as "unshared" objects, or false otherwise.
The getOffset method returns the offset of the field's value within instance data of the class defining the field.
The setOffset method allows ObjectStreamField subclasses to modify the offset value returned by the getOffset method.
The compareTo method compares ObjectStreamFields 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.
CONTENTS | PREV | NEXT