Java™ Platform
Standard Ed. 8
compact1, compact2, compact3
java.io
Class ObjectStreamField
-
- All Implemented Interfaces:
- Comparable<Object>
public class ObjectStreamField
extends Object
implements Comparable<Object>
A description of a Serializable field from a Serializable class. An array
of ObjectStreamFields is used to declare the Serializable fields of a class.
- Since:
- 1.2
- See Also:
ObjectStreamClass
-
-
Constructor Summary
Constructors
| Constructor |
Description |
ObjectStreamField(String name,
Class<?> type) |
Create a Serializable field with the specified type.
|
ObjectStreamField(String name,
Class<?> type,
boolean unshared) |
Creates an ObjectStreamField representing a serializable field with the
given name and type.
|
-
Method Summary
All Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
int |
compareTo(Object obj) |
Compare this field with another ObjectStreamField.
|
String |
getName() |
Get the name of this field.
|
int |
getOffset() |
Offset of field within instance data.
|
Class<?> |
getType() |
Get the type of the field.
|
char |
getTypeCode() |
Returns character encoding of field type.
|
String |
getTypeString() |
Return the JVM type signature.
|
boolean |
isPrimitive() |
Return true if this field has a primitive type.
|
boolean |
isUnshared() |
Returns boolean value indicating whether or not the serializable field
represented by this ObjectStreamField instance is unshared.
|
protected void |
setOffset(int offset) |
Offset within instance data.
|
String |
toString() |
Return a string that describes this field.
|
-
-
Constructor Detail
-
ObjectStreamField
public ObjectStreamField(String name,
Class<?> type)
Create a Serializable field with the specified type. This field should
be documented with a serialField tag.
- Parameters:
name - the name of the serializable field
type - the Class object of the serializable field
-
ObjectStreamField
public ObjectStreamField(String name,
Class<?> type,
boolean unshared)
Creates an ObjectStreamField representing a serializable field with the
given name and type. If unshared is false, values of the represented
field are serialized and deserialized in the default manner--if the
field is non-primitive, object values are serialized and deserialized as
if they had been written and read by calls to writeObject and
readObject. If unshared is true, values of the represented field are
serialized and deserialized as if they had been written and read by
calls to writeUnshared and readUnshared.
- Parameters:
name - field name
type - field type
unshared - if false, write/read field values in the same manner
as writeObject/readObject; if true, write/read in the same
manner as writeUnshared/readUnshared
- Since:
- 1.4
-
Method Detail
-
compareTo
public int compareTo(Object obj)
Compare this field with another ObjectStreamField. Return
-1 if this is smaller, 0 if equal, 1 if greater. Types that are
primitives are "smaller" than object types. If equal, the field names
are compared.
- Specified by:
compareTo in interface Comparable<Object>
- Parameters:
obj - the object to be compared.
- Returns:
- a negative integer, zero, or a positive integer as this object
is less than, equal to, or greater than the specified object.
Java™ Platform
Standard Ed. 8
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.