Java.io.ObjectStreamClass.forClass() Method
Advertisements
Description
The java.io.ObjectStreamClass.forClass() method returns the class in the local VM that this version is mapped to. Null is returned if there is no corresponding local class.
Declaration
Following is the declaration for java.io.ObjectStreamClass.forClass() method
public Class<?> forClass()
Parameters
NA
Return Value
This method returns the Class instance that this descriptor represents
Exception
NA
Example
The following example shows the usage of java.io.ObjectStreamClass.forClass() method.
package com.tutorialspoint;
import java.io.*;
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 Class instance for osc
System.out.println("" + osc.forClass());
// create a new object stream class for Strings
ObjectStreamClass osc2 = ObjectStreamClass.lookup(String.class);
// get the Class instance for osc
System.out.println("" + osc2.forClass());
}
}
Let us compile and run the above program, this will produce the following result:
class java.lang.Integer class java.lang.String