Java.io.ObjectStreamClass.lookup() Method
Advertisements
Description
The java.io.ObjectStreamClass.lookup(Class<?> cl) method finds 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.
Declaration
Following is the declaration for java.io.ObjectStreamClass.lookup() method
public static ObjectStreamClass lookup(Class<?> cl)
Parameters
cl -- class for which to get the descriptor
Return Value
This method returns the class descriptor for the specified class
Exception
NA
Example
The following example shows the usage of java.io.ObjectStreamClass.lookup() method.
package com.tutorialspoint;
import java.io.*;
import java.util.Calendar;
public class ObjectStreamClassDemo {
public static void main(String[] args) {
// create a new object stream class for Integers
ObjectStreamClass osc = ObjectStreamClass.lookup(Integer.class);
// get the name for Integers
System.out.println("" + osc.getName());
// create a new object stream class for Calendar
ObjectStreamClass osc2 = ObjectStreamClass.lookup(Calendar.class);
// get the name for Calendar
System.out.println("" + osc2.getName());
}
}
Let us compile and run the above program, this will produce the following result:
java.lang.Integer java.util.Calendar