Class ObjectStreamClass in Java
This class is used to represent a class that is being serialized. An ObjectStreamClass object contains the name of a class and its unique version identifier. This class does not have a constructor; we should use the static lookup() method to obtain an ObjectStreamClass object for a given Class object.
When an object is deserialized, its class information is read into an ObjectStreamClass, which is then resolved to a Class if possible. An ObjectStreamClass instance contains the name and version information for a class.
The forClass() instance method performs the opposite operation-it returns the Class object that corresponds to a given ObjectStreamClass.
Most applications never need to use this class.
The class structure of class ObjectStreamClass is given as
public class java.io.ObjectStreamClass extends java.lang.Object implements java.io.Serializable {
// No Constructor
// Class Methods
public static ObjectStreamClass lookup(Class class);
// Public Instance Methods
public Class forClass();
public String getName();
public long getSerialVersionUID();
public String toString(); // Overrides Object
}
The details of the class ObjectStreamClass is given as:
public static ObjectStreamClass lookup(Class class);
public static ObjectStreamClass lookup(Class class) method finds an ObjectStreamClass for the given Class. If the appropriate ObjectStreamClass does not already exist, this method creates an ObjectStreamClass for the given Class. The method returns null if cl is not serializable.
This method returns an ObjectStreamClass that corresponds to the given Class.
Parameter
class-The Class to find.
public Class forClass();
public Class forClass() method returns the Class in the run-time system that corresponds to this ObjectStreamClass. If there is no corresponding class, null is returned.
This method returns the Class that corresponds to this ObjectStreamClass.
public String getName();
public String getName() method returns the name of the class this ObjectStreamClass represents.
This method returns the class name.
public long getSerialVersionUID();
public long getSerialVersionUID() method returns the version of the class this ObjectStreamClass represents.
This method returns the class version.
public String toString(); // Overrides Object
public String toString() method returns a string that contains the class name and version information for this
ObjectStreamClass.
This method returns a string representation of this object.
Apart from these ObjectStreamClass class also has inherited methods from class- Object. They are as follows:
- clone()
- finalize()
- hashCode()
- notifyAll()
- wait()
- wait(long, int)
- equals(Object)
- getClass()
- notify()
- toString()
- wait(long)