Class ObjectStreamClass

java.lang.Object
java.io.ObjectStreamClass
All Implemented Interfaces:
Serializable

public final class ObjectStreamClass extends Object implements Serializable
Serialization's descriptor for classes. It contains the name and serialVersionUID of the class. The ObjectStreamClass for a specific class loaded in this Java VM can be found/created using the lookup method.

The algorithm to compute the SerialVersionUID is described in Java Object Serialization Specification, Section 4.6, "Stream Unique Identifiers".

Since:
1.1
External Specifications
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ObjectStreamField[]
    serialPersistentFields value indicating no serializable fields
  • Method Summary

    Modifier and Type
    Method
    Description
    Return the class in the local VM that this version is mapped to.
    Get the field of this class by name.
    Return an array of the fields of this serializable class.
    Returns the name of the class described by this descriptor.
    long
    Return the serialVersionUID for this class.
    lookup(Class<?> cl)
    Find the descriptor for a class that can be serialized.
    Returns the descriptor for any class, regardless of whether it implements Serializable.
    Return a string describing this ObjectStreamClass.

    Methods declared in class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
    Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.
    boolean
    Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    May cause performance issues, deadlocks and hangs.
    final Class<? extends Object>
    Answers the unique instance of java.lang.Class which represents the class of the receiver.
    int
    Answers an integer hash code for the receiver.
    final void
    Causes one thread which is waiting on the receiver to be made ready to run.
    final void
    Causes all threads which are waiting on the receiver to be made ready to run.
    final void
    Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated by notify or notifyAll).
    final void
    wait(long time)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
    final void
    wait(long time, int frac)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
  • Field Details

    • NO_FIELDS

      public static final ObjectStreamField[] NO_FIELDS
      serialPersistentFields value indicating no serializable fields
  • Method Details

    • lookup

      public static ObjectStreamClass lookup(Class<?> cl)
      Find the descriptor for a class that can be serialized. Creates an ObjectStreamClass instance if one does not exist yet for class. Null is returned if the specified class does not implement java.io.Serializable or java.io.Externalizable.
      Parameters:
      cl - class for which to get the descriptor
      Returns:
      the class descriptor for the specified class
    • lookupAny

      public static ObjectStreamClass lookupAny(Class<?> cl)
      Returns the descriptor for any class, regardless of whether it implements Serializable.
      Parameters:
      cl - class for which to get the descriptor
      Returns:
      the class descriptor for the specified class
      Since:
      1.6
    • getName

      public String getName()
      Returns the name of the class described by this descriptor. This method returns the name of the class in the format that is used by the Class.getName() method.
      Returns:
      a string representing the name of the class
    • getSerialVersionUID

      public long getSerialVersionUID()
      Return the serialVersionUID for this class. The serialVersionUID defines a set of classes all with the same name that have evolved from a common root class and agree to be serialized and deserialized using a common format. NonSerializable classes have a serialVersionUID of 0L.
      Returns:
      the SUID of the class described by this descriptor
    • forClass

      public Class<?> forClass()
      Return the class in the local VM that this version is mapped to. Null is returned if there is no corresponding local class.
      Returns:
      the Class instance that this descriptor represents
    • getFields

      public ObjectStreamField[] getFields()
      Return an array of the fields of this serializable class.
      Returns:
      an array containing an element for each persistent field of this class. Returns an array of length zero if there are no fields.
      Since:
      1.2
    • getField

      public ObjectStreamField getField(String name)
      Get the field of this class by name.
      Parameters:
      name - the name of the data field to look for
      Returns:
      The ObjectStreamField object of the named field or null if there is no such named field.
    • toString

      public String toString()
      Return a string describing this ObjectStreamClass.
      Overrides:
      toString in class Object
      Returns:
      String a printable representation for the receiver.