Package java.io
Class ObjectStreamField
java.lang.Object
java.io.ObjectStreamField
- All Implemented Interfaces:
Comparable<Object>
public class ObjectStreamField extends Object implements Comparable<Object>
Describes a field for the purpose of serialization. Classes can define the
collection of fields that are serialized, which may be different from the set
of all declared fields.
-
Constructor Summary
Constructors Constructor Description ObjectStreamField(String name, Class<?> cl)Constructs an ObjectStreamField with the specified name and type.ObjectStreamField(String name, Class<?> cl, boolean unshared)Constructs an ObjectStreamField with the specified name, type and the indication if it is unshared. -
Method Summary
Modifier and Type Method Description intcompareTo(Object o)Compares this field descriptor to the specified one.StringgetName()Gets the name of this field.intgetOffset()Gets the offset of this field in the object.Class<?>getType()Gets the type of this field.chargetTypeCode()Gets a character code for the type of this field.StringgetTypeString()Gets the type signature used by the VM to represent the type of this field.booleanisPrimitive()Indicates whether this field's type is a primitive type.booleanisUnshared()Indicates whether this field is unshared.protected voidsetOffset(int newValue)Sets this field's offset in the object.StringtoString()Returns a string containing a concise, human-readable description of this field descriptor.
-
Constructor Details
-
ObjectStreamField
Constructs an ObjectStreamField with the specified name and type.- Parameters:
name- the name of the field.cl- the type of the field.- Throws:
NullPointerException- ifnameorclisnull.
-
ObjectStreamField
Constructs an ObjectStreamField with the specified name, type and the indication if it is unshared.- Parameters:
name- the name of the field.cl- the type of the field.unshared-trueif the field is written and read unshared;falseotherwise.- Throws:
NullPointerException- ifnameorclisnull.- See Also:
ObjectOutputStream.writeUnshared(Object)
-
-
Method Details
-
compareTo
Compares this field descriptor to the specified one. Checks first if one of the compared fields has a primitive type and the other one not. If so, the field with the primitive type is considered to be "smaller". If both fields are equal, their names are compared.- Specified by:
compareToin interfaceComparable<Object>- Parameters:
o- the object to compare with.- Returns:
- -1 if this field is "smaller" than field
o, 0 if both fields are equal; 1 if this field is "greater" than fieldo.
-
getName
Gets the name of this field.- Returns:
- the field's name.
-
getOffset
public int getOffset()Gets the offset of this field in the object.- Returns:
- this field's offset.
-
getType
Gets the type of this field.- Returns:
- a
Classobject representing the type of the field.
-
getTypeCode
public char getTypeCode()Gets a character code for the type of this field. The following codes are used:B byte C char D double F float I int J long L class or interface S short Z boolean [ array
- Returns:
- the field's type code.
-
getTypeString
Gets the type signature used by the VM to represent the type of this field.- Returns:
- the signature of this field's class or
nullif this field's type is primitive.
-
isPrimitive
public boolean isPrimitive()Indicates whether this field's type is a primitive type.- Returns:
trueif this field's type is primitive;falseif the type of this field is a regular class.
-
setOffset
protected void setOffset(int newValue)Sets this field's offset in the object.- Parameters:
newValue- the field's new offset.
-
toString
Returns a string containing a concise, human-readable description of this field descriptor.
-